diff --git a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md index 7e02596f7b..02e0e6c914 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md +++ b/docs/content/doc/advanced/config-cheat-sheet.zh-cn.md @@ -84,14 +84,14 @@ menu: ## Database (`database`) -- `DB_TYPE`: 数据库类型,可选 `mysql`, `postgres`, `mssql`, `tidb` 或 `sqlite3`。 +- `DB_TYPE`: 数据库类型,可选 `mysql`, `postgres`, `mssql` 或 `sqlite3`。 - `HOST`: 数据库服务器地址和端口。 - `NAME`: 数据库名称。 - `USER`: 数据库用户名。 - `PASSWD`: 数据库用户密码。 - `SSL_MODE`: MySQL 或 PostgreSQL数据库是否启用SSL模式。 - `CHARSET`: **utf8mb4**: 仅当数据库为 MySQL 时有效, 可以为 "utf8" 或 "utf8mb4"。注意:如果使用 "utf8mb4",你的 MySQL InnoDB 版本必须在 5.6 以上。 -- `PATH`: Tidb 或者 SQLite3 数据文件存放路径。 +- `PATH`: SQLite3 数据文件存放路径。 - `LOG_SQL`: **true**: 显示生成的SQL,默认为真。 - `MAX_IDLE_CONNS` **0**: 最大空闲数据库连接 - `CONN_MAX_LIFETIME` **3s**: 数据库连接最大存活时间 diff --git a/docs/content/page/index.en-us.md b/docs/content/page/index.en-us.md index 48ca13cc66..087278a83f 100644 --- a/docs/content/page/index.en-us.md +++ b/docs/content/page/index.en-us.md @@ -73,7 +73,7 @@ Windows, on architectures like amd64, i386, ARM, PowerPC, and others. - PostgreSQL (>=10) - SQLite3 - MSSQL (>=2008R2 SP3) - - TiDB (experimental, not recommended) + - TiDB (MySQL protocol) - Configuration file - [app.ini](https://github.com/go-gitea/gitea/blob/master/custom/conf/app.example.ini) - Admin panel diff --git a/docs/content/page/index.fr-fr.md b/docs/content/page/index.fr-fr.md index 17e22e8b59..711e163deb 100755 --- a/docs/content/page/index.fr-fr.md +++ b/docs/content/page/index.fr-fr.md @@ -68,7 +68,7 @@ Le but de ce projet est de fournir de la manière la plus simple, la plus rapide - PostgreSQL - SQLite3 - MSSQL - - [TiDB](https://github.com/pingcap/tidb) (expérimental) + - [TiDB](https://github.com/pingcap/tidb) (MySQL protocol) - Fichier de configuration - Voir [ici](https://github.com/go-gitea/gitea/blob/master/custom/conf/app.example.ini) - Panel d'administration diff --git a/docs/content/page/index.zh-cn.md b/docs/content/page/index.zh-cn.md index cb6a1da793..9aa1e6a8bc 100644 --- a/docs/content/page/index.zh-cn.md +++ b/docs/content/page/index.zh-cn.md @@ -32,7 +32,7 @@ Gitea的首要目标是创建一个极易安装,运行非常快速,安装和 - 支持自定义源的 Gravatar 和 Federated Avatar - 支持邮件服务 - 支持后台管理面板 -- 支持 MySQL、PostgreSQL、SQLite3, MSSQL 和 TiDB(实验性支持) 数据库 +- 支持 MySQL、PostgreSQL、SQLite3、MSSQL 和 TiDB(MySQL) 数据库 - 支持多语言本地化(21 种语言) ## 系统要求 diff --git a/docs/content/page/index.zh-tw.md b/docs/content/page/index.zh-tw.md index 488dac16ad..e475f6f214 100644 --- a/docs/content/page/index.zh-tw.md +++ b/docs/content/page/index.zh-tw.md @@ -69,7 +69,7 @@ Gitea 是從 [Gogs](http://gogs.io) Fork 出來的,請閱讀部落格文章 [G - PostgreSQL - SQLite3 - MSSQL - - TiDB(實驗中, 不建議使用) + - TiDB(MySQL 協議) - 設定檔 - [app.ini](https://github.com/go-gitea/gitea/blob/master/custom/conf/app.example.ini) - 管理員面板 diff --git a/models/engine_test.go b/models/engine_test.go index 75c854b185..6f4d114db3 100644 --- a/models/engine_test.go +++ b/models/engine_test.go @@ -28,8 +28,7 @@ func TestDumpDatabase(t *testing.T) { } assert.NoError(t, db.GetEngine(db.DefaultContext).Sync2(new(Version))) - for _, dbName := range setting.SupportedDatabases { - dbType := setting.GetDBTypeByName(dbName) + for _, dbType := range setting.SupportedDatabaseTypes { assert.NoError(t, db.DumpDatabase(filepath.Join(dir, dbType+".sql"), dbType)) } } diff --git a/modules/setting/database.go b/modules/setting/database.go index 02b5e43f4a..8db1cd13eb 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -16,9 +16,10 @@ import ( ) var ( - // SupportedDatabases includes all supported databases type - SupportedDatabases = []string{"MySQL", "PostgreSQL", "MSSQL"} - dbTypes = map[string]string{"MySQL": "mysql", "PostgreSQL": "postgres", "MSSQL": "mssql", "SQLite3": "sqlite3"} + // SupportedDatabaseTypes includes all XORM supported databases type, sqlite3 maybe added by `database_sqlite3.go` + SupportedDatabaseTypes = []string{"mysql", "postgres", "mssql"} + // DatabaseTypeNames contains the friendly names for all database types + DatabaseTypeNames = map[string]string{"mysql": "MySQL", "postgres": "PostgreSQL", "mssql": "MSSQL", "sqlite3": "SQLite3"} // EnableSQLite3 use SQLite3, set by build flag EnableSQLite3 bool @@ -52,11 +53,6 @@ var ( } ) -// GetDBTypeByName returns the database type as it defined on XORM according the given name -func GetDBTypeByName(name string) string { - return dbTypes[name] -} - // InitDBConfig loads the database settings func InitDBConfig() { sec := Cfg.Section("database") diff --git a/modules/setting/database_sqlite.go b/modules/setting/database_sqlite.go index 798292fec8..12c60cc86c 100644 --- a/modules/setting/database_sqlite.go +++ b/modules/setting/database_sqlite.go @@ -13,5 +13,5 @@ import ( func init() { EnableSQLite3 = true - SupportedDatabases = append(SupportedDatabases, "SQLite3") + SupportedDatabaseTypes = append(SupportedDatabaseTypes, "sqlite3") } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 772189b0ae..b1f8b7994b 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -124,7 +124,7 @@ license_desc = Go get documentation before changing any settings. -requite_db_desc = Gitea requires MySQL, PostgreSQL, MSSQL or SQLite3. +require_db_desc = Gitea requires MySQL, PostgreSQL, MSSQL, SQLite3 or TiDB (MySQL protocol). db_title = Database Settings db_type = Database Type host = Host 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 diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl index b419d04a1b..2a27baf535 100644 --- a/templates/admin/config.tmpl +++ b/templates/admin/config.tmpl @@ -119,7 +119,7 @@