Skip to content

Commit

Permalink
chore: some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tankerkiller125 committed Oct 19, 2024
1 parent c0e605a commit 2d6b05e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
13 changes: 7 additions & 6 deletions backend/app/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
"time"

atlas "ariga.io/atlas/sql/migrate"
Expand Down Expand Up @@ -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}")
}
Expand Down
5 changes: 3 additions & 2 deletions backend/app/tools/migrations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down

0 comments on commit 2d6b05e

Please sign in to comment.