2019-06-08 19:23:45 +05:30
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2019-06-08 19:23:45 +05:30
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
2019-06-08 19:23:45 +05:30
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
2023-07-21 14:58:19 +05:30
|
|
|
"github.com/urfave/cli/v2"
|
2019-06-08 19:23:45 +05:30
|
|
|
)
|
|
|
|
|
2023-07-25 20:08:27 +05:30
|
|
|
// cmdDoctorConvert represents the available convert sub-command.
|
|
|
|
var cmdDoctorConvert = &cli.Command{
|
2019-06-08 19:23:45 +05:30
|
|
|
Name: "convert",
|
|
|
|
Usage: "Convert the database",
|
2024-04-04 21:32:24 +05:30
|
|
|
Description: "A command to convert an existing MySQL database from utf8 to utf8mb4",
|
2023-07-25 20:08:27 +05:30
|
|
|
Action: runDoctorConvert,
|
2019-06-08 19:23:45 +05:30
|
|
|
}
|
|
|
|
|
2023-07-25 20:08:27 +05:30
|
|
|
func runDoctorConvert(ctx *cli.Context) error {
|
2021-11-07 08:41:27 +05:30
|
|
|
stdCtx, cancel := installSignals()
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
if err := initDB(stdCtx); err != nil {
|
2019-06-08 19:23:45 +05:30
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-06-27 06:26:58 +05:30
|
|
|
log.Info("AppPath: %s", setting.AppPath)
|
|
|
|
log.Info("AppWorkPath: %s", setting.AppWorkPath)
|
|
|
|
log.Info("Custom path: %s", setting.CustomPath)
|
2023-02-19 21:42:01 +05:30
|
|
|
log.Info("Log path: %s", setting.Log.RootPath)
|
2021-09-14 06:54:57 +05:30
|
|
|
log.Info("Configuration file: %s", setting.CustomConf)
|
2019-06-08 19:23:45 +05:30
|
|
|
|
2024-04-04 21:32:24 +05:30
|
|
|
if setting.Database.Type.IsMySQL() {
|
2024-01-10 16:33:23 +05:30
|
|
|
if err := db.ConvertDatabaseTable(); err != nil {
|
|
|
|
log.Fatal("Failed to convert database & table: %v", err)
|
2023-04-17 18:52:10 +05:30
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")
|
2024-04-04 21:32:24 +05:30
|
|
|
} else {
|
|
|
|
fmt.Println("This command can only be used with a MySQL database")
|
2019-06-08 19:23:45 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|