diff --git a/modules/setting/database.go b/modules/setting/database.go index 49865a38a2840..892bb2b2e8a99 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -61,22 +61,12 @@ func LoadDBSetting() { sec := CfgProvider.Section("database") Database.Type = sec.Key("DB_TYPE").String() defaultCharset := "utf8" - Database.UseMySQL = false - Database.UseSQLite3 = false - Database.UsePostgreSQL = false - Database.UseMSSQL = false - switch Database.Type { - case "sqlite3": - Database.UseSQLite3 = true - case "mysql": - Database.UseMySQL = true + EnsureDBType() + if Database.UseMySQL { defaultCharset = "utf8mb4" - case "postgres": - Database.UsePostgreSQL = true - case "mssql": - Database.UseMSSQL = true } + Database.Host = sec.Key("HOST").String() Database.Name = sec.Key("NAME").String() Database.User = sec.Key("USER").String() @@ -109,6 +99,25 @@ func LoadDBSetting() { Database.AutoMigration = sec.Key("AUTO_MIGRATION").MustBool(true) } +// EnsureDBType ensures Database.UseXXX has been set to the right value +func EnsureDBType() { + Database.UseMySQL = false + Database.UseSQLite3 = false + Database.UsePostgreSQL = false + Database.UseMSSQL = false + + switch Database.Type { + case "sqlite3": + Database.UseSQLite3 = true + case "mysql": + Database.UseMySQL = true + case "postgres": + Database.UsePostgreSQL = true + case "mssql": + Database.UseMSSQL = true + } +} + // DBConnStr returns database connection string func DBConnStr() (string, error) { var connStr string diff --git a/routers/install/install.go b/routers/install/install.go index a377c2950ba31..ecc7a46c5a4f7 100644 --- a/routers/install/install.go +++ b/routers/install/install.go @@ -273,6 +273,7 @@ func SubmitInstall(ctx *context.Context) { // Test database setting. setting.Database.Type = form.DbType + setting.EnsureDBType() setting.Database.Host = form.DbHost setting.Database.User = form.DbUser setting.Database.Passwd = form.DbPasswd