mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-21 12:44:49 -05:00
Remove "CHARSET" config option for MySQL, always use "utf8mb4" (#25413)
In modern days, there is no reason to make users set "charset" anymore. Close #25378 ## ⚠️ BREAKING The key `[database].CHARSET` was removed completely as every newer (>10years) MySQL database supports `utf8mb4` already. There is a (deliberately) undocumented new fallback option if anyone still needs to use it, but we don't recommend using it as it simply causes problems.
This commit is contained in:
parent
dfd19fa38c
commit
ce46834b93
8 changed files with 9 additions and 46 deletions
|
@ -344,9 +344,6 @@ NAME = gitea
|
|||
USER = root
|
||||
;PASSWD = ;Use PASSWD = `your password` for quoting if you use special characters in the password.
|
||||
;SSL_MODE = false ; either "false" (default), "true", or "skip-verify"
|
||||
;CHARSET = utf8mb4 ;either "utf8" or "utf8mb4", default is "utf8mb4".
|
||||
;;
|
||||
;; NOTICE: for "utf8mb4" you must use MySQL InnoDB > 5.6. Gitea is unable to check this.
|
||||
;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
|
|
|
@ -443,7 +443,6 @@ The following configuration set `Content-Type: application/vnd.android.package-a
|
|||
- `SQLITE_TIMEOUT`: **500**: Query timeout for SQLite3 only.
|
||||
- `SQLITE_JOURNAL_MODE`: **""**: Change journal mode for SQlite3. Can be used to enable [WAL mode](https://www.sqlite.org/wal.html) when high load causes write congestion. See [SQlite3 docs](https://www.sqlite.org/pragma.html#pragma_journal_mode) for possible values. Defaults to the default for the database file, often DELETE.
|
||||
- `ITERATE_BUFFER_SIZE`: **50**: Internal buffer size for iterating.
|
||||
- `CHARSET`: **utf8mb4**: For MySQL only, either "utf8" or "utf8mb4". NOTICE: for "utf8mb4" you must use MySQL InnoDB > 5.6. Gitea is unable to check this.
|
||||
- `PATH`: **data/gitea.db**: For SQLite3 only, the database file path.
|
||||
- `LOG_SQL`: **true**: Log the executed SQL.
|
||||
- `DB_RETRIES`: **10**: How many ORM init / DB connect attempts allowed.
|
||||
|
|
|
@ -396,8 +396,6 @@ Please run `gitea convert`, or run `ALTER DATABASE database_name CHARACTER SET u
|
|||
for the database_name and run `ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;`
|
||||
for each table in the database.
|
||||
|
||||
You will also need to change the app.ini database charset to `CHARSET=utf8mb4`.
|
||||
|
||||
## Why are Emoji displaying only as placeholders or in monochrome
|
||||
|
||||
Gitea requires the system or browser to have one of the supported Emoji fonts installed, which are Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji and Twemoji Mozilla. Generally, the operating system should already provide one of these fonts, but especially on Linux, it may be necessary to install them manually.
|
||||
|
|
|
@ -12,8 +12,6 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -36,7 +34,7 @@ var (
|
|||
SSLMode string
|
||||
Path string
|
||||
LogSQL bool
|
||||
Charset string
|
||||
MysqlCharset string
|
||||
Timeout int // seconds
|
||||
SQLiteJournalMode string
|
||||
DBConnectRetries int
|
||||
|
@ -60,11 +58,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,10 +67,7 @@ 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.MysqlCharset = sec.Key("MYSQL_CHARSET").MustString("utf8mb4") // do not document it, end users won't need it.
|
||||
|
||||
Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db"))
|
||||
Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
|
||||
|
@ -101,9 +91,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 +106,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.MysqlCharset, 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 +126,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
|
||||
|
|
|
@ -197,11 +197,9 @@ host = Host
|
|||
user = Username
|
||||
password = Password
|
||||
db_name = Database Name
|
||||
db_helper = Note to MySQL users: please use the InnoDB storage engine and if you use "utf8mb4", your InnoDB version must be greater than 5.6 .
|
||||
db_schema = Schema
|
||||
db_schema_helper = Leave blank for database default ("public").
|
||||
ssl_mode = SSL
|
||||
charset = Charset
|
||||
path = Path
|
||||
sqlite_helper = File path for the SQLite3 database.<br>Enter an absolute path if you run Gitea as a service.
|
||||
reinstall_error = You are trying to install into an existing Gitea database
|
||||
|
|
|
@ -99,7 +99,6 @@ func Install(ctx *context.Context) {
|
|||
form.DbName = setting.Database.Name
|
||||
form.DbPath = setting.Database.Path
|
||||
form.DbSchema = setting.Database.Schema
|
||||
form.Charset = setting.Database.Charset
|
||||
|
||||
curDBType := setting.Database.Type.String()
|
||||
var isCurDBTypeSupported bool
|
||||
|
@ -269,7 +268,6 @@ func SubmitInstall(ctx *context.Context) {
|
|||
setting.Database.Name = form.DbName
|
||||
setting.Database.Schema = form.DbSchema
|
||||
setting.Database.SSLMode = form.SSLMode
|
||||
setting.Database.Charset = form.Charset
|
||||
setting.Database.Path = form.DbPath
|
||||
setting.Database.LogSQL = !setting.IsProd
|
||||
|
||||
|
@ -388,7 +386,6 @@ func SubmitInstall(ctx *context.Context) {
|
|||
cfg.Section("database").Key("PASSWD").SetValue(setting.Database.Passwd)
|
||||
cfg.Section("database").Key("SCHEMA").SetValue(setting.Database.Schema)
|
||||
cfg.Section("database").Key("SSL_MODE").SetValue(setting.Database.SSLMode)
|
||||
cfg.Section("database").Key("CHARSET").SetValue(setting.Database.Charset)
|
||||
cfg.Section("database").Key("PATH").SetValue(setting.Database.Path)
|
||||
cfg.Section("database").Key("LOG_SQL").SetValue("false") // LOG_SQL is rarely helpful
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ type InstallForm struct {
|
|||
DbPasswd string
|
||||
DbName string
|
||||
SSLMode string
|
||||
Charset string `binding:"Required;In(utf8,utf8mb4)"`
|
||||
DbPath string
|
||||
DbSchema string
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
<div class="inline required field {{if .Err_DbSetting}}error{{end}}">
|
||||
<label for="db_name">{{.locale.Tr "install.db_name"}}</label>
|
||||
<input id="db_name" name="db_name" value="{{.db_name}}">
|
||||
<span class="help">{{.locale.Tr "install.db_helper"}}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -69,20 +68,6 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gt-hidden" data-db-setting-for="mysql">
|
||||
<div class="inline required field">
|
||||
<label>{{.locale.Tr "install.charset"}}</label>
|
||||
<div class="ui selection database type dropdown">
|
||||
<input type="hidden" name="charset" value="{{if .charset}}{{.charset}}{{else}}utf8mb4{{end}}">
|
||||
<div class="default text">utf8mb4</div>
|
||||
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
|
||||
<div class="menu">
|
||||
<div class="item" data-value="utf8mb4">utf8mb4</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gt-hidden" data-db-setting-for="sqlite3">
|
||||
<div class="inline required field {{if or .Err_DbPath .Err_DbSetting}}error{{end}}">
|
||||
<label for="db_path">{{.locale.Tr "install.path"}}</label>
|
||||
|
|
Loading…
Reference in a new issue