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 | |
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')
-rw-r--r-- | routers/admin/admin.go | 4 | ||||
-rw-r--r-- | routers/init.go | 19 | ||||
-rw-r--r-- | routers/install.go | 62 |
3 files changed, 39 insertions, 46 deletions
diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 54fbddc58e..496aca375f 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -289,7 +289,7 @@ func Config(ctx *context.Context) { ctx.Data["LFS"] = setting.LFS ctx.Data["Service"] = setting.Service - ctx.Data["DbCfg"] = models.DbCfg + ctx.Data["DbCfg"] = setting.Database ctx.Data["Webhook"] = setting.Webhook ctx.Data["MailerEnabled"] = false @@ -333,7 +333,7 @@ func Config(ctx *context.Context) { ctx.Data["AccessLogTemplate"] = setting.AccessLogTemplate ctx.Data["DisableRouterLog"] = setting.DisableRouterLog ctx.Data["EnableXORMLog"] = setting.EnableXORMLog - ctx.Data["LogSQL"] = setting.LogSQL + ctx.Data["LogSQL"] = setting.Database.LogSQL ctx.HTML(200, tplConfig) } diff --git a/routers/init.go b/routers/init.go index 4724da8627..fdf90904ce 100644 --- a/routers/init.go +++ b/routers/init.go @@ -47,16 +47,16 @@ func NewServices() { // In case of problems connecting to DB, retry connection. Eg, PGSQL in Docker Container on Synology func initDBEngine() (err error) { log.Info("Beginning ORM engine initialization.") - for i := 0; i < setting.DBConnectRetries; i++ { - log.Info("ORM engine initialization attempt #%d/%d...", i+1, setting.DBConnectRetries) + for i := 0; i < setting.Database.DBConnectRetries; i++ { + log.Info("ORM engine initialization attempt #%d/%d...", i+1, setting.Database.DBConnectRetries) if err = models.NewEngine(migrations.Migrate); err == nil { break - } else if i == setting.DBConnectRetries-1 { + } else if i == setting.Database.DBConnectRetries-1 { return err } - log.Error("ORM engine initialization attempt #%d/%d failed. Error: %v", i+1, setting.DBConnectRetries, err) - log.Info("Backing off for %d seconds", int64(setting.DBConnectBackoff/time.Second)) - time.Sleep(setting.DBConnectBackoff) + log.Error("ORM engine initialization attempt #%d/%d failed. Error: %v", i+1, setting.Database.DBConnectRetries, err) + log.Info("Backing off for %d seconds", int64(setting.Database.DBConnectBackoff/time.Second)) + time.Sleep(setting.Database.DBConnectBackoff) } models.HasEngine = true return nil @@ -73,7 +73,7 @@ func GlobalInit() { log.Trace("AppWorkPath: %s", setting.AppWorkPath) log.Trace("Custom path: %s", setting.CustomPath) log.Trace("Log path: %s", setting.LogRootPath) - models.LoadConfigs() + NewServices() if setting.InstallLock { @@ -102,12 +102,9 @@ func GlobalInit() { models.InitDeliverHooks() models.InitTestPullRequests() } - if models.EnableSQLite3 { + if setting.EnableSQLite3 { log.Info("SQLite3 Supported") } - if models.EnableTiDB { - log.Info("TiDB Supported") - } checkRunMode() if setting.InstallLock && setting.SSH.StartBuiltinServer { 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) |