Skip to content

Commit 7e7326a

Browse files
committed
if a table is already using utf8mb4, do not convert it again.
1 parent dca09f8 commit 7e7326a

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

docs/content/help/faq.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ the `utf8` charset, and connections which use the `utf8` charset will not use th
387387

388388
Please run `gitea doctor convert`, or run `ALTER DATABASE database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;`
389389
for the database_name and run `ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;`
390-
for each table in the database.
390+
for tables which are not using `utf8mb4` in the database.
391391

392392
## Why are Emoji displaying only as placeholders or in monochrome
393393

docs/content/help/faq.zh-cn.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,7 @@ SET GLOBAL innodb_large_prefix=1;
390390
utf8 字符集的表和连接将不会使用它。
391391

392392
请运行 `gitea doctor convert` 或对数据库运行 `ALTER DATABASE database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;`
393-
并对每个表运行 `ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;`
394-
395-
您还需要将`app.ini`文件中的数据库字符集设置为`CHARSET=utf8mb4`
393+
并对不是 `utf8mb4` 的表运行 `ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;`
396394

397395
## 为什么 Emoji 只显示占位符或单色图像
398396

models/db/convert.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package db
66
import (
77
"fmt"
88
"strconv"
9+
"strings"
910

1011
"code.gitea.io/gitea/modules/log"
1112
"code.gitea.io/gitea/modules/setting"
@@ -34,6 +35,10 @@ func ConvertUtf8ToUtf8mb4() error {
3435
return err
3536
}
3637

38+
if strings.HasPrefix(table.Collation, "utf8mb4") {
39+
fmt.Printf("skip table %q because it is already using utf8mb4\n", table.Name)
40+
continue
41+
}
3742
if _, err := x.Exec(fmt.Sprintf("ALTER TABLE `%s` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;", table.Name)); err != nil {
3843
return err
3944
}

0 commit comments

Comments
 (0)