aboutsummaryrefslogtreecommitdiffstats
path: root/routers/install
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2021-12-07 13:44:08 +0800
committerGitHub <noreply@github.com>2021-12-07 13:44:08 +0800
commita6f961fba416e146f5da6cb18115d2f6251d4fe3 (patch)
tree53f437167ca3720510d29e17081d0eaa1d1a9521 /routers/install
parentb30870ef8bcf98bdf0f0829955fc8599a75e26df (diff)
downloadgitea-a6f961fba416e146f5da6cb18115d2f6251d4fe3.tar.gz
gitea-a6f961fba416e146f5da6cb18115d2f6251d4fe3.zip
Refactor install page (db type) (#17919)
* Refactor install page (db type) * set correct default DB HOST for different DB TYPE * remove legacy TiDB from documents * unify the usage of DB TYPE, in code we only use "mysql". "MySQL" is only shown to users for friendly name. * Gitea can use TiDB via MySQL protocol Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'routers/install')
-rw-r--r--routers/install/install.go37
1 files changed, 23 insertions, 14 deletions
diff --git a/routers/install/install.go b/routers/install/install.go
index b2f04b14dd..45804acf3b 100644
--- a/routers/install/install.go
+++ b/routers/install/install.go
@@ -42,6 +42,16 @@ const (
tplPostInstall base.TplName = "post-install"
)
+var supportedDbTypeNames []map[string]string // use a slice to keep order
+func getDbTypeNames() []map[string]string {
+ if supportedDbTypeNames == nil {
+ for _, t := range setting.SupportedDatabaseTypes {
+ supportedDbTypeNames = append(supportedDbTypeNames, map[string]string{"type": t, "name": setting.DatabaseTypeNames[t]})
+ }
+ }
+ return supportedDbTypeNames
+}
+
// Init prepare for rendering installation page
func Init(next http.Handler) http.Handler {
var rnd = templates.HTMLRenderer()
@@ -63,7 +73,7 @@ func Init(next http.Handler) http.Handler {
Data: map[string]interface{}{
"Title": locale.Tr("install.install"),
"PageIsInstall": true,
- "DbOptions": setting.SupportedDatabases,
+ "DbTypeNames": getDbTypeNames(),
"i18n": locale,
"Language": locale.Language(),
"Lang": locale.Language(),
@@ -100,19 +110,18 @@ func Install(ctx *context.Context) {
form.DbSchema = setting.Database.Schema
form.Charset = setting.Database.Charset
- var curDBOption = "MySQL"
- switch setting.Database.Type {
- case "postgres":
- curDBOption = "PostgreSQL"
- case "mssql":
- curDBOption = "MSSQL"
- case "sqlite3":
- if setting.EnableSQLite3 {
- curDBOption = "SQLite3"
+ curDBType := setting.Database.Type
+ var isCurDBTypeSupported bool
+ for _, dbType := range setting.SupportedDatabaseTypes {
+ if dbType == curDBType {
+ isCurDBTypeSupported = true
+ break
}
}
-
- ctx.Data["CurDbOption"] = curDBOption
+ if !isCurDBTypeSupported {
+ curDBType = "mysql"
+ }
+ ctx.Data["CurDbType"] = curDBType
// Application general settings
form.AppName = setting.AppName
@@ -237,7 +246,7 @@ func SubmitInstall(ctx *context.Context) {
form.AppURL += "/"
}
- ctx.Data["CurDbOption"] = form.DbType
+ ctx.Data["CurDbType"] = form.DbType
if ctx.HasError() {
if ctx.HasValue("Err_SMTPUser") {
@@ -261,7 +270,7 @@ func SubmitInstall(ctx *context.Context) {
// ---- Basic checks are passed, now test configuration.
// Test database setting.
- setting.Database.Type = setting.GetDBTypeByName(form.DbType)
+ setting.Database.Type = form.DbType
setting.Database.Host = form.DbHost
setting.Database.User = form.DbUser
setting.Database.Passwd = form.DbPasswd