diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-08-24 17:24:45 +0800 |
---|---|---|
committer | Antoine GIRARD <sapk@users.noreply.github.com> | 2019-08-24 11:24:45 +0200 |
commit | f83db078f0603c775cd1b1bb016f996b65a04835 (patch) | |
tree | 9895f852c768d43b384ba36259b44d9506b04093 /routers/install.go | |
parent | 26af3401c36e6316b81b92bf6a776bf2442d251c (diff) | |
download | gitea-f83db078f0603c775cd1b1bb016f996b65a04835.tar.gz gitea-f83db078f0603c775cd1b1bb016f996b65a04835.zip |
Move database settings from models to setting (#7806)
* move database settings from models to setting
* update docs
* fix checkout pr
* fix tests
* fix lint
* remove unsupported tidb options
* correct wrong variable name
* remove tidb totally
Diffstat (limited to 'routers/install.go')
-rw-r--r-- | routers/install.go | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/routers/install.go b/routers/install.go index 6d29bcf887..16888adc82 100644 --- a/routers/install.go +++ b/routers/install.go @@ -40,11 +40,7 @@ func InstallInit(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("install.install") ctx.Data["PageIsInstall"] = true - dbOpts := []string{"MySQL", "PostgreSQL", "MSSQL"} - if models.EnableSQLite3 { - dbOpts = append(dbOpts, "SQLite3") - } - ctx.Data["DbOptions"] = dbOpts + ctx.Data["DbOptions"] = setting.SupportedDatabases } // Install render installation page @@ -52,21 +48,21 @@ func Install(ctx *context.Context) { form := auth.InstallForm{} // Database settings - form.DbHost = models.DbCfg.Host - form.DbUser = models.DbCfg.User - form.DbPasswd = models.DbCfg.Passwd - form.DbName = models.DbCfg.Name - form.DbPath = models.DbCfg.Path - form.Charset = models.DbCfg.Charset + form.DbHost = setting.Database.Host + form.DbUser = setting.Database.User + form.DbPasswd = setting.Database.Passwd + form.DbName = setting.Database.Name + form.DbPath = setting.Database.Path + form.Charset = setting.Database.Charset ctx.Data["CurDbOption"] = "MySQL" - switch models.DbCfg.Type { + switch setting.Database.Type { case "postgres": ctx.Data["CurDbOption"] = "PostgreSQL" case "mssql": ctx.Data["CurDbOption"] = "MSSQL" case "sqlite3": - if models.EnableSQLite3 { + if setting.EnableSQLite3 { ctx.Data["CurDbOption"] = "SQLite3" } } @@ -144,18 +140,18 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) { // Pass basic check, now test configuration. // Test database setting. - dbTypes := map[string]string{"MySQL": "mysql", "PostgreSQL": "postgres", "MSSQL": "mssql", "SQLite3": "sqlite3"} - models.DbCfg.Type = dbTypes[form.DbType] - models.DbCfg.Host = form.DbHost - models.DbCfg.User = form.DbUser - models.DbCfg.Passwd = form.DbPasswd - models.DbCfg.Name = form.DbName - models.DbCfg.SSLMode = form.SSLMode - models.DbCfg.Charset = form.Charset - models.DbCfg.Path = form.DbPath - - if (models.DbCfg.Type == "sqlite3") && - len(models.DbCfg.Path) == 0 { + + setting.Database.Type = setting.GetDBTypeByName(form.DbType) + setting.Database.Host = form.DbHost + setting.Database.User = form.DbUser + setting.Database.Passwd = form.DbPasswd + setting.Database.Name = form.DbName + setting.Database.SSLMode = form.SSLMode + setting.Database.Charset = form.Charset + setting.Database.Path = form.DbPath + + if (setting.Database.Type == "sqlite3") && + len(setting.Database.Path) == 0 { ctx.Data["Err_DbPath"] = true ctx.RenderWithErr(ctx.Tr("install.err_empty_db_path"), tplInstall, &form) return @@ -265,14 +261,14 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) { log.Error("Failed to load custom conf '%s': %v", setting.CustomConf, err) } } - cfg.Section("database").Key("DB_TYPE").SetValue(models.DbCfg.Type) - cfg.Section("database").Key("HOST").SetValue(models.DbCfg.Host) - cfg.Section("database").Key("NAME").SetValue(models.DbCfg.Name) - cfg.Section("database").Key("USER").SetValue(models.DbCfg.User) - cfg.Section("database").Key("PASSWD").SetValue(models.DbCfg.Passwd) - cfg.Section("database").Key("SSL_MODE").SetValue(models.DbCfg.SSLMode) - cfg.Section("database").Key("CHARSET").SetValue(models.DbCfg.Charset) - cfg.Section("database").Key("PATH").SetValue(models.DbCfg.Path) + cfg.Section("database").Key("DB_TYPE").SetValue(setting.Database.Type) + cfg.Section("database").Key("HOST").SetValue(setting.Database.Host) + cfg.Section("database").Key("NAME").SetValue(setting.Database.Name) + cfg.Section("database").Key("USER").SetValue(setting.Database.User) + cfg.Section("database").Key("PASSWD").SetValue(setting.Database.Passwd) + cfg.Section("database").Key("SSL_MODE").SetValue(setting.Database.SSLMode) + cfg.Section("database").Key("CHARSET").SetValue(setting.Database.Charset) + cfg.Section("database").Key("PATH").SetValue(setting.Database.Path) cfg.Section("").Key("APP_NAME").SetValue(form.AppName) cfg.Section("repository").Key("ROOT").SetValue(form.RepoRootPath) |