mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 11:52:10 +00:00
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>
This commit is contained in:
parent
b30870ef8b
commit
a6f961fba4
14 changed files with 75 additions and 80 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue