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.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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/db"
  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. stdCtx, cancel := installSignals()
  21. defer cancel()
  22. if err := initDB(stdCtx); err != nil {
  23. return err
  24. }
  25. log.Info("AppPath: %s", setting.AppPath)
  26. log.Info("AppWorkPath: %s", setting.AppWorkPath)
  27. log.Info("Custom path: %s", setting.CustomPath)
  28. log.Info("Log path: %s", setting.LogRootPath)
  29. log.Info("Configuration file: %s", setting.CustomConf)
  30. setting.InitDBConfig()
  31. if !setting.Database.UseMySQL {
  32. fmt.Println("This command can only be used with a MySQL database")
  33. return nil
  34. }
  35. if err := db.ConvertUtf8ToUtf8mb4(); err != nil {
  36. log.Fatal("Failed to convert database from utf8 to utf8mb4: %v", err)
  37. return err
  38. }
  39. fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")
  40. return nil
  41. }