From 2df7563f3176aa8c7dcb070f660d53da4bb66e78 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 10 Jan 2024 19:03:23 +0800 Subject: Recommend/convert to use case-sensitive collation for MySQL/MSSQL (#28662) Mainly for MySQL/MSSQL. It is important for Gitea to use case-sensitive database charset collation. If the database is using a case-insensitive collation, Gitea will show startup error/warning messages, and show the errors/warnings on the admin panel's Self-Check page. Make `gitea doctor convert` work for MySQL to convert the collations of database & tables & columns. * Fix #28131 ## :warning: BREAKING :warning: It is not quite breaking, but it's highly recommended to convert the database&table&column to a consistent and case-sensitive collation. --- modules/setting/database.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'modules/setting') diff --git a/modules/setting/database.go b/modules/setting/database.go index 015c918d93..0b0488ce85 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -35,6 +35,7 @@ var ( Path string LogSQL bool MysqlCharset string + CharsetCollation string Timeout int // seconds SQLiteJournalMode string DBConnectRetries int @@ -67,7 +68,7 @@ func loadDBSetting(rootCfg ConfigProvider) { } Database.Schema = sec.Key("SCHEMA").String() Database.SSLMode = sec.Key("SSL_MODE").MustString("disable") - Database.MysqlCharset = sec.Key("MYSQL_CHARSET").MustString("utf8mb4") // do not document it, end users won't need it. + Database.CharsetCollation = sec.Key("CHARSET_COLLATION").String() Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db")) Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500) @@ -105,8 +106,8 @@ func DBConnStr() (string, error) { if tls == "disable" { // allow (Postgres-inspired) default value to work in MySQL tls = "false" } - connStr = fmt.Sprintf("%s:%s@%s(%s)/%s%scharset=%s&parseTime=true&tls=%s", - Database.User, Database.Passwd, connType, Database.Host, Database.Name, paramSep, Database.MysqlCharset, tls) + connStr = fmt.Sprintf("%s:%s@%s(%s)/%s%sparseTime=true&tls=%s", + Database.User, Database.Passwd, connType, Database.Host, Database.Name, paramSep, tls) case "postgres": connStr = getPostgreSQLConnectionString(Database.Host, Database.User, Database.Passwd, Database.Name, Database.SSLMode) case "mssql": -- cgit v1.2.3