Skip to content

Commit

Permalink
init db: fix: specifying env db url requires repo config file
Browse files Browse the repository at this point in the history
Specifying the postgresql url via the BAUR_POSTGRESQL_URL environment
variable only works when a baur repository config file exist.
When the repository config file is not found, it fails with an error.

This is not intentional, skip searching and reading the repository
config if the BAUR_POSTGRESQL_URL environment variable is set.
  • Loading branch information
fho committed Jul 16, 2024
1 parent 657eb8f commit a62e324
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions internal/command/init_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package command
import (
"errors"
"fmt"
"os"
"strings"

"github.com/spf13/cobra"

"github.com/simplesurance/baur/v5/internal/command/term"
"github.com/simplesurance/baur/v5/pkg/baur"
"github.com/simplesurance/baur/v5/pkg/storage"
)

Expand Down Expand Up @@ -45,20 +43,9 @@ func initDb(_ *cobra.Command, args []string) {
if len(args) == 1 {
dbURL = args[0]
} else {
repo, err := findRepository()
if err != nil {
if os.IsNotExist(err) {
stderr.Printf("could not find '%s' repository config file.\n"+
"Run '%s' first or pass the Postgres URL as argument.\n",
term.Highlight(baur.RepositoryCfgFile), term.Highlight(cmdInitRepo))
exitFunc(exitCodeError)
}

stderr.Println(err)
exitFunc(exitCodeError)
}

dbURL = mustGetPSQLURI(repo.Cfg)
var err error
dbURL, err = postgresqlURL()
exitOnErr(err)
}

storageClt, err := newStorageClient(dbURL)
Expand Down

0 comments on commit a62e324

Please sign in to comment.