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.

migrate.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2018 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. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/models/migrations"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/setting"
  10. "github.com/urfave/cli"
  11. )
  12. // CmdMigrate represents the available migrate sub-command.
  13. var CmdMigrate = cli.Command{
  14. Name: "migrate",
  15. Usage: "Migrate the database",
  16. Description: "This is a command for migrating the database, so that you can run gitea admin create-user before starting the server.",
  17. Action: runMigrate,
  18. Flags: []cli.Flag{
  19. cli.StringFlag{
  20. Name: "config, c",
  21. Value: "custom/conf/app.ini",
  22. Usage: "Custom configuration file path",
  23. },
  24. },
  25. }
  26. func runMigrate(ctx *cli.Context) error {
  27. if ctx.IsSet("config") {
  28. setting.CustomConf = ctx.String("config")
  29. }
  30. if err := initDB(); err != nil {
  31. return err
  32. }
  33. log.Trace("AppPath: %s", setting.AppPath)
  34. log.Trace("AppWorkPath: %s", setting.AppWorkPath)
  35. log.Trace("Custom path: %s", setting.CustomPath)
  36. log.Trace("Log path: %s", setting.LogRootPath)
  37. models.LoadConfigs()
  38. if err := models.NewEngine(migrations.Migrate); err != nil {
  39. log.Fatal(4, "Failed to initialize ORM engine: %v", err)
  40. return err
  41. }
  42. return nil
  43. }