本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3KB

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package cmd
  5. import (
  6. "fmt"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/setting"
  10. "github.com/urfave/cli"
  11. )
  12. // CmdConvert represents the available convert sub-command.
  13. var CmdConvert = cli.Command{
  14. Name: "convert",
  15. Usage: "Convert the database",
  16. Description: "A command to convert an existing MySQL database from utf8 to utf8mb4",
  17. Action: runConvert,
  18. }
  19. func runConvert(ctx *cli.Context) error {
  20. if err := initDB(); err != nil {
  21. return err
  22. }
  23. log.Trace("AppPath: %s", setting.AppPath)
  24. log.Trace("AppWorkPath: %s", setting.AppWorkPath)
  25. log.Trace("Custom path: %s", setting.CustomPath)
  26. log.Trace("Log path: %s", setting.LogRootPath)
  27. setting.InitDBConfig()
  28. if !setting.Database.UseMySQL {
  29. fmt.Println("This command can only be used with a MySQL database")
  30. return nil
  31. }
  32. if err := models.ConvertUtf8ToUtf8mb4(); err != nil {
  33. log.Fatal("Failed to convert database from utf8 to utf8mb4: %v", err)
  34. return err
  35. }
  36. fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")
  37. return nil
  38. }
上海开阖软件有限公司 沪ICP备12045867号-1