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.

convert.go 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package cmd
  4. import (
  5. "fmt"
  6. "code.gitea.io/gitea/models/db"
  7. "code.gitea.io/gitea/modules/log"
  8. "code.gitea.io/gitea/modules/setting"
  9. "github.com/urfave/cli"
  10. )
  11. // CmdConvert represents the available convert sub-command.
  12. var CmdConvert = cli.Command{
  13. Name: "convert",
  14. Usage: "Convert the database",
  15. Description: "A command to convert an existing MySQL database from utf8 to utf8mb4",
  16. Action: runConvert,
  17. }
  18. func runConvert(ctx *cli.Context) error {
  19. stdCtx, cancel := installSignals()
  20. defer cancel()
  21. if err := initDB(stdCtx); err != nil {
  22. return err
  23. }
  24. log.Info("AppPath: %s", setting.AppPath)
  25. log.Info("AppWorkPath: %s", setting.AppWorkPath)
  26. log.Info("Custom path: %s", setting.CustomPath)
  27. log.Info("Log path: %s", setting.LogRootPath)
  28. log.Info("Configuration file: %s", setting.CustomConf)
  29. if !setting.Database.UseMySQL {
  30. fmt.Println("This command can only be used with a MySQL database")
  31. return nil
  32. }
  33. if err := db.ConvertUtf8ToUtf8mb4(); err != nil {
  34. log.Fatal("Failed to convert database from utf8 to utf8mb4: %v", err)
  35. return err
  36. }
  37. fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")
  38. return nil
  39. }