From 2d6b05e30a2b39649ab0103c837c5c8bb8c19b2f Mon Sep 17 00:00:00 2001 From: Matt Kilgore Date: Sat, 19 Oct 2024 17:15:23 -0400 Subject: [PATCH] chore: some cleanup --- backend/app/api/main.go | 13 +++++++------ backend/app/tools/migrations/main.go | 5 +++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/backend/app/api/main.go b/backend/app/api/main.go index 490467fa..54560905 100644 --- a/backend/app/api/main.go +++ b/backend/app/api/main.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "path/filepath" + "strings" "time" atlas "ariga.io/atlas/sql/migrate" @@ -84,22 +85,22 @@ func run(cfg *config.Config) error { // Set up the database URL based on the driver because for some reason a common URL format is not used databaseURL := "" - switch { - case cfg.Database.Driver == "sqlite3": + switch strings.ToLower(cfg.Database.Driver) { + case "sqlite3": databaseURL = cfg.Database.SqlitePath - case cfg.Database.Driver == "mysql": + case "mysql": databaseURL = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?parseTime=true", cfg.Database.Username, cfg.Database.Password, cfg.Database.Host, cfg.Database.Port, cfg.Database.Database) - case cfg.Database.Driver == "postgres": + case "postgres": databaseURL = fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", cfg.Database.Host, cfg.Database.Port, cfg.Database.Username, cfg.Database.Password, cfg.Database.Database, cfg.Database.SslMode) default: log.Fatal().Str("driver", cfg.Database.Driver).Msg("unsupported database driver {driver}") } - c, err := ent.Open(cfg.Database.Driver, databaseURL) + c, err := ent.Open(strings.ToLower(cfg.Database.Driver), databaseURL) if err != nil { log.Fatal(). Err(err). - Str("driver", cfg.Database.Driver). + Str("driver", strings.ToLower(cfg.Database.Driver)). Str("url", databaseURL). Msg("failed opening connection to {driver} database at {url}") } diff --git a/backend/app/tools/migrations/main.go b/backend/app/tools/migrations/main.go index 034ec0dd..fb233615 100644 --- a/backend/app/tools/migrations/main.go +++ b/backend/app/tools/migrations/main.go @@ -6,6 +6,7 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/sys/config" "log" "os" + "strings" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/migrate" @@ -24,8 +25,8 @@ func main() { panic(err) } sqlDialect := "" - switch cfg.Database.Driver { - case "sqlite": + switch strings.ToLower(cfg.Database.Driver) { + case "sqlite3": sqlDialect = dialect.SQLite case "mysql": sqlDialect = dialect.MySQL