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