Skip to content

Commit

Permalink
if a table is already using utf8mb4, do not convert it again.
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Dec 29, 2023
1 parent dca09f8 commit 7e7326a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/content/help/faq.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ the `utf8` charset, and connections which use the `utf8` charset will not use th

Please run `gitea doctor convert`, or run `ALTER DATABASE database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;`
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.
for tables which are not using `utf8mb4` in the database.

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

Expand Down
4 changes: 1 addition & 3 deletions docs/content/help/faq.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,7 @@ SET GLOBAL innodb_large_prefix=1;
utf8 字符集的表和连接将不会使用它。

请运行 `gitea doctor convert` 或对数据库运行 `ALTER DATABASE database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;`
并对每个表运行 `ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;`

您还需要将`app.ini`文件中的数据库字符集设置为`CHARSET=utf8mb4`
并对不是 `utf8mb4` 的表运行 `ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;`

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

Expand Down
5 changes: 5 additions & 0 deletions models/db/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package db
import (
"fmt"
"strconv"
"strings"

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
Expand Down Expand Up @@ -34,6 +35,10 @@ func ConvertUtf8ToUtf8mb4() error {
return err
}

if strings.HasPrefix(table.Collation, "utf8mb4") {
fmt.Printf("skip table %q because it is already using utf8mb4\n", table.Name)

Check failure on line 39 in models/db/convert.go

View workflow job for this annotation

GitHub Actions / lint-backend

use of `fmt.Printf` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)

Check failure on line 39 in models/db/convert.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

use of `fmt.Printf` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)

Check failure on line 39 in models/db/convert.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

use of `fmt.Printf` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
continue
}
if _, err := x.Exec(fmt.Sprintf("ALTER TABLE `%s` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;", table.Name)); err != nil {
return err
}
Expand Down

0 comments on commit 7e7326a

Please sign in to comment.