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

Ensure setting.Database.UseXXX has been set to the right value when installing #23350

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 22 additions & 13 deletions modules/setting/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions routers/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down