diff --git a/config/local.yaml b/config/local.yaml index f9c888f..0dcaaf4 100644 --- a/config/local.yaml +++ b/config/local.yaml @@ -8,6 +8,12 @@ pushover: database: type: "sqlite" migration: true + # these are only required for postgres + host: "secret" + port: "secret" + user: "secret" + password: "secret" + name: "secret" jwt: secret: "secret" session_time: 168h diff --git a/config/selfhosted.yaml b/config/selfhosted.yaml index 26e2eb5..9911907 100644 --- a/config/selfhosted.yaml +++ b/config/selfhosted.yaml @@ -8,6 +8,12 @@ pushover: database: type: "sqlite" migration: true + # these are only required for postgres + host: "secret" + port: "secret" + user: "secret" + password: "secret" + name: "secret" jwt: secret: "secret" session_time: 168h diff --git a/internal/database/migration.go b/internal/database/migration.go index cfca864..54e7eb2 100644 --- a/internal/database/migration.go +++ b/internal/database/migration.go @@ -3,7 +3,9 @@ package database import ( "embed" "fmt" - "os" + + migrate "github.com/rubenv/sql-migrate" + "gorm.io/gorm" "donetick.com/core/config" chModel "donetick.com/core/internal/chore/model" @@ -13,9 +15,7 @@ import ( stModel "donetick.com/core/internal/subtask/model" tModel "donetick.com/core/internal/thing/model" uModel "donetick.com/core/internal/user/model" // Pure go SQLite driver, checkout https://github.com/glebarez/sqlite for details - migrations "donetick.com/core/migrations" - migrate "github.com/rubenv/sql-migrate" - "gorm.io/gorm" + "donetick.com/core/migrations" ) //go:embed migrations/*.sql @@ -52,9 +52,14 @@ func MigrationScripts(gormDB *gorm.DB, cfg *config.Config) error { Root: "migrations", } - path := os.Getenv("DT_SQLITE_PATH") - if path == "" { - path = "donetick.db" + var dialect string + switch cfg.Database.Type { + case "postgres": + dialect = "postgres" + case "sqlite": + dialect = "sqlite3" + default: + return fmt.Errorf("unsupported database type: %s", cfg.Database.Type) } db, err := gormDB.DB() @@ -62,7 +67,7 @@ func MigrationScripts(gormDB *gorm.DB, cfg *config.Config) error { return err } - n, err := migrate.Exec(db, "sqlite3", migrations, migrate.Up) + n, err := migrate.Exec(db, dialect, migrations, migrate.Up) if err != nil { return err }