Skip to content

Commit

Permalink
Accept postgresql://-schemed database URLs (#532)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandur Leach <brandur@brandur.org>
  • Loading branch information
yawboakye and brandur authored Aug 19, 2024
1 parent 25bfd99 commit d1bedc7
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 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,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.
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit d1bedc7

Please sign in to comment.