From d3a30ed807666067aca09dabeaa2eab0315b72e0 Mon Sep 17 00:00:00 2001 From: yaw Date: Mon, 19 Aug 2024 14:56:45 +0100 Subject: [PATCH] Accept `postgresql://`-schemed database URLs (#532) Co-authored-by: Brandur Leach --- cmd/river/rivercli/command.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/river/rivercli/command.go b/cmd/river/rivercli/command.go index b2ee032d..1ac0df94 100644 --- a/cmd/river/rivercli/command.go +++ b/cmd/river/rivercli/command.go @@ -2,7 +2,6 @@ package rivercli import ( "context" - "errors" "fmt" "io" "log/slog" @@ -17,6 +16,11 @@ import ( "github.com/riverqueue/river/rivermigrate" ) +const ( + uriScheme = "postgresql://" + uriSchemeAlias = "postgres://" +) + // BenchmarkerInterface is an interface to a Benchmarker. Its reason for // existence is to wrap a benchmarker to strip it of its generic parameter, // letting us pass it around without having to know the transaction type. @@ -90,7 +94,8 @@ func RunCommand[TOpts CommandOpts](ctx context.Context, bundle *RunCommandBundle commandBase.GetBenchmarker = func() BenchmarkerInterface { panic("databaseURL was not set") } commandBase.GetMigrator = func(config *rivermigrate.Config) MigratorInterface { panic("databaseURL was not set") } - case strings.HasPrefix(*bundle.DatabaseURL, "postgres://"): + case strings.HasPrefix(*bundle.DatabaseURL, uriScheme) || + strings.HasPrefix(*bundle.DatabaseURL, uriSchemeAlias): dbPool, err := openPgxV5DBPool(ctx, *bundle.DatabaseURL) if err != nil { return false, err @@ -103,7 +108,12 @@ func RunCommand[TOpts CommandOpts](ctx context.Context, bundle *RunCommandBundle commandBase.GetMigrator = func(config *rivermigrate.Config) MigratorInterface { return rivermigrate.New(driver, config) } default: - return false, errors.New("unsupport database URL; try one with a prefix of `postgres://...`") + return false, fmt.Errorf( + "unsupported database URL (`%s`); try one with a `%s` or `%s` scheme/prefix", + *bundle.DatabaseURL, + uriSchemeAlias, + uriScheme, + ) } command.SetCommandBase(commandBase)