summaryrefslogtreecommitdiffstats
path: root/modules/setting/database.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/setting/database.go')
-rw-r--r--modules/setting/database.go26
1 files changed, 11 insertions, 15 deletions
diff --git a/modules/setting/database.go b/modules/setting/database.go
index 7a7c7029a4..bb259f1fea 100644
--- a/modules/setting/database.go
+++ b/modules/setting/database.go
@@ -60,11 +60,6 @@ func LoadDBSetting() {
func loadDBSetting(rootCfg ConfigProvider) {
sec := rootCfg.Section("database")
Database.Type = DatabaseType(sec.Key("DB_TYPE").String())
- defaultCharset := "utf8"
-
- if Database.Type.IsMySQL() {
- defaultCharset = "utf8mb4"
- }
Database.Host = sec.Key("HOST").String()
Database.Name = sec.Key("NAME").String()
@@ -74,9 +69,10 @@ func loadDBSetting(rootCfg ConfigProvider) {
}
Database.Schema = sec.Key("SCHEMA").String()
Database.SSLMode = sec.Key("SSL_MODE").MustString("disable")
- Database.Charset = sec.Key("CHARSET").In(defaultCharset, []string{"utf8", "utf8mb4"})
- if Database.Type.IsMySQL() && defaultCharset != "utf8mb4" {
- log.Error("Deprecated database mysql charset utf8 support, please use utf8mb4 or convert utf8 to utf8mb4.")
+
+ Database.Charset = sec.Key("CHARSET").MustString("utf8mb4")
+ if Database.Type.IsMySQL() && Database.Charset != "utf8mb4" {
+ log.Error(`Deprecated database mysql charset utf8 support, please use utf8mb4 and convert utf8 database to utf8mb4 by "gitea convert".`)
}
Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db"))
@@ -101,9 +97,9 @@ func loadDBSetting(rootCfg ConfigProvider) {
// DBConnStr returns database connection string
func DBConnStr() (string, error) {
var connStr string
- Param := "?"
- if strings.Contains(Database.Name, Param) {
- Param = "&"
+ paramSep := "?"
+ if strings.Contains(Database.Name, paramSep) {
+ paramSep = "&"
}
switch Database.Type {
case "mysql":
@@ -116,15 +112,15 @@ func DBConnStr() (string, error) {
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, Param, Database.Charset, tls)
+ Database.User, Database.Passwd, connType, Database.Host, Database.Name, paramSep, Database.Charset, tls)
case "postgres":
- connStr = getPostgreSQLConnectionString(Database.Host, Database.User, Database.Passwd, Database.Name, Param, Database.SSLMode)
+ connStr = getPostgreSQLConnectionString(Database.Host, Database.User, Database.Passwd, Database.Name, paramSep, Database.SSLMode)
case "mssql":
host, port := ParseMSSQLHostPort(Database.Host)
connStr = fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;", host, port, Database.Name, Database.User, Database.Passwd)
case "sqlite3":
if !EnableSQLite3 {
- return "", errors.New("this binary version does not build support for SQLite3")
+ return "", errors.New("this Gitea binary was not built with SQLite3 support")
}
if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil {
return "", fmt.Errorf("Failed to create directories: %w", err)
@@ -136,7 +132,7 @@ func DBConnStr() (string, error) {
connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate%s",
Database.Path, Database.Timeout, journalMode)
default:
- return "", fmt.Errorf("Unknown database type: %s", Database.Type)
+ return "", fmt.Errorf("unknown database type: %s", Database.Type)
}
return connStr, nil