2019-06-08 22:53:45 +09:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-28 03:20:29 +09:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-06-08 22:53:45 +09:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-09-19 20:49:59 +09:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2019-06-08 22:53:45 +09:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CmdConvert represents the available convert sub-command.
|
|
|
|
var CmdConvert = cli.Command{
|
|
|
|
Name: "convert",
|
|
|
|
Usage: "Convert the database",
|
|
|
|
Description: "A command to convert an existing MySQL database from utf8 to utf8mb4",
|
|
|
|
Action: runConvert,
|
|
|
|
}
|
|
|
|
|
|
|
|
func runConvert(ctx *cli.Context) error {
|
2021-11-07 12:11:27 +09:00
|
|
|
stdCtx, cancel := installSignals()
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
if err := initDB(stdCtx); err != nil {
|
2019-06-08 22:53:45 +09:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-06-27 09:56:58 +09:00
|
|
|
log.Info("AppPath: %s", setting.AppPath)
|
|
|
|
log.Info("AppWorkPath: %s", setting.AppWorkPath)
|
|
|
|
log.Info("Custom path: %s", setting.CustomPath)
|
2023-02-20 01:12:01 +09:00
|
|
|
log.Info("Log path: %s", setting.Log.RootPath)
|
2021-09-14 10:24:57 +09:00
|
|
|
log.Info("Configuration file: %s", setting.CustomConf)
|
2019-06-08 22:53:45 +09:00
|
|
|
|
2023-03-07 19:51:06 +09:00
|
|
|
if !setting.Database.Type.IsMySQL() {
|
2019-06-08 22:53:45 +09:00
|
|
|
fmt.Println("This command can only be used with a MySQL database")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-19 20:49:59 +09:00
|
|
|
if err := db.ConvertUtf8ToUtf8mb4(); err != nil {
|
2019-06-08 22:53:45 +09:00
|
|
|
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
|
|
|
|
}
|