Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

convert.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. if !setting.Database.UseMySQL {
  31. fmt.Println("This command can only be used with a MySQL database")
  32. return nil
  33. }
  34. if err := db.ConvertUtf8ToUtf8mb4(); err != nil {
  35. log.Fatal("Failed to convert database from utf8 to utf8mb4: %v", err)
  36. return err
  37. }
  38. fmt.Println("Converted successfully, please confirm your database's character set is now utf8mb4")
  39. return nil
  40. }