Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept postgresql://-schemed database URLs #532

Merged
merged 4 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions cmd/river/rivercli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rivercli

import (
"context"
"errors"
"fmt"
"io"
"log/slog"
Expand All @@ -17,6 +16,16 @@ import (
"github.com/riverqueue/river/rivermigrate"
)

const (
// Referencing the offical PostgreSQL documentation, it appears that
// `postgresql://` is the default/preferred URI scheme, with `postgres://`
// as the fallback. River accepts both.
//
// See https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS.
yawboakye marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down Expand Up @@ -90,7 +99,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
Expand All @@ -103,7 +113,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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/river/rivercli/river_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Provides command line facilities for the River job queue.
}

addDatabaseURLFlag := func(cmd *cobra.Command, databaseURL *string) {
cmd.Flags().StringVar(databaseURL, "database-url", "", "URL of the database to benchmark (should look like `postgres://...`")
cmd.Flags().StringVar(databaseURL, "database-url", "", "URL of the database to benchmark (should look like `postgres://...` or `postgresql://...`")
yawboakye marked this conversation as resolved.
Show resolved Hide resolved
mustMarkFlagRequired(cmd, "database-url")
}
addLineFlag := func(cmd *cobra.Command, line *string) {
Expand Down
Loading