aboutsummaryrefslogtreecommitdiffstats
path: root/modules/setting/database.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-08-22 13:56:33 +0100
committerGitHub <noreply@github.com>2020-08-22 13:56:33 +0100
commitfcabbae1686b82cb495d8d430279b745a707f377 (patch)
tree74e98aead89c1637cdad2ab192a8523fa64ddf2d /modules/setting/database.go
parentb78448e94e1415eb810ee1126135c64ec2942c0f (diff)
downloadgitea-fcabbae1686b82cb495d8d430279b745a707f377.tar.gz
gitea-fcabbae1686b82cb495d8d430279b745a707f377.zip
Set utf8mb4 as the default charset on MySQL if CHARSET is unset (#12563)
MySQL in its infinite wisdom determines that UTF8 does not mean UTF8. Our install scripts know about this and will set CHARSET to utf8mb4 if we users choose this but... users who do not explicitly set this variable will default to utf8mb3 without knowing it. This PR changes the unset CHARSET value to utf8mb4 if users choose to use mysql. Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/setting/database.go')
-rw-r--r--modules/setting/database.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/modules/setting/database.go b/modules/setting/database.go
index a0734bc67a..d5d03c2a30 100644
--- a/modules/setting/database.go
+++ b/modules/setting/database.go
@@ -60,11 +60,13 @@ func GetDBTypeByName(name string) string {
func InitDBConfig() {
sec := Cfg.Section("database")
Database.Type = sec.Key("DB_TYPE").String()
+ defaultCharset := "utf8"
switch Database.Type {
case "sqlite3":
Database.UseSQLite3 = true
case "mysql":
Database.UseMySQL = true
+ defaultCharset = "utf8mb4"
case "postgres":
Database.UsePostgreSQL = true
case "mssql":
@@ -78,7 +80,7 @@ func InitDBConfig() {
}
Database.Schema = sec.Key("SCHEMA").String()
Database.SSLMode = sec.Key("SSL_MODE").MustString("disable")
- Database.Charset = sec.Key("CHARSET").In("utf8", []string{"utf8", "utf8mb4"})
+ Database.Charset = sec.Key("CHARSET").In(defaultCharset, []string{"utf8", "utf8mb4"})
Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db"))
Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(2)