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

Attempt to continue when encountering errors in createDBIfNotExist #258

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Changes from all commits
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
10 changes: 6 additions & 4 deletions pkg/drivers/pgsql/pgsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,15 @@ func createDBIfNotExist(dataSourceName string) error {
u.Path = "/postgres"
db, err := sql.Open("pgx", u.String())
if err != nil {
return err
logrus.Warnf("failed to ensure existence of database %s: unable to connect to default postgres database: %v", dbName, err)
return nil
}
defer db.Close()

var exists bool
err = db.QueryRow("SELECT 1 FROM pg_database WHERE datname = $1", dbName).Scan(&exists)
if err != nil && err != sql.ErrNoRows {
return err
logrus.Warnf("failed to check existence of database %s, going to attempt create: %v", dbName, err)
}

stmt := createDB + dbName + ";"
Expand All @@ -153,9 +154,10 @@ func createDBIfNotExist(dataSourceName string) error {
logrus.Tracef("SETUP EXEC : %v", util.Stripped(stmt))
_, err = db.Exec(stmt)
mortenlj marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
logrus.Warnf("failed to create database %s: %v", dbName, err)
} else {
logrus.Tracef("created database: %s", dbName)
}
logrus.Tracef("created database: %s", dbName)
}
return nil
brandond marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down