aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/convert.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-04-17 21:22:10 +0800
committerGitHub <noreply@github.com>2023-04-17 21:22:10 +0800
commitcda84bec87f18fa5cbbbd62fc72bc3d997aba66c (patch)
tree63e39cd88f8b16456a781d9a8cc743f833ff3694 /cmd/convert.go
parentdcde4701a5b31c88b3120722c3163af4214264d2 (diff)
downloadgitea-cda84bec87f18fa5cbbbd62fc72bc3d997aba66c.tar.gz
gitea-cda84bec87f18fa5cbbbd62fc72bc3d997aba66c.zip
Support converting varchar to nvarchar for mssql database (#24105)
Diffstat (limited to 'cmd/convert.go')
-rw-r--r--cmd/convert.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/cmd/convert.go b/cmd/convert.go
index d9b89495c1..8c7746fdf2 100644
--- a/cmd/convert.go
+++ b/cmd/convert.go
@@ -17,7 +17,7 @@ import (
var CmdConvert = cli.Command{
Name: "convert",
Usage: "Convert the database",
- Description: "A command to convert an existing MySQL database from utf8 to utf8mb4",
+ Description: "A command to convert an existing MySQL database from utf8 to utf8mb4 or MSSQL database from varchar to nvarchar",
Action: runConvert,
}
@@ -35,17 +35,22 @@ func runConvert(ctx *cli.Context) error {
log.Info("Log path: %s", setting.Log.RootPath)
log.Info("Configuration file: %s", setting.CustomConf)
- if !setting.Database.Type.IsMySQL() {
- fmt.Println("This command can only be used with a MySQL database")
- return nil
+ switch {
+ case setting.Database.Type.IsMySQL():
+ if err := db.ConvertUtf8ToUtf8mb4(); err != nil {
+ log.Fatal("Failed to convert database from utf8 to utf8mb4: %v", err)
+ return err
+ }
+ fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")
+ case setting.Database.Type.IsMSSQL():
+ if err := db.ConvertVarcharToNVarchar(); err != nil {
+ log.Fatal("Failed to convert database from varchar to nvarchar: %v", err)
+ return err
+ }
+ fmt.Println("Converted successfully, please confirm your database's all columns character is NVARCHAR now")
+ default:
+ fmt.Println("This command can only be used with a MySQL or MSSQL database")
}
- if err := db.ConvertUtf8ToUtf8mb4(); err != nil {
- log.Fatal("Failed to convert database from utf8 to utf8mb4: %v", err)
- return err
- }
-
- fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")
-
return nil
}