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

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. "context"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/models/migrations"
  9. "code.gitea.io/gitea/modules/log"
  10. "code.gitea.io/gitea/modules/setting"
  11. "github.com/urfave/cli"
  12. )
  13. // CmdMigrate represents the available migrate sub-command.
  14. var CmdMigrate = cli.Command{
  15. Name: "migrate",
  16. Usage: "Migrate the database",
  17. Description: "This is a command for migrating the database, so that you can run gitea admin create-user before starting the server.",
  18. Action: runMigrate,
  19. }
  20. func runMigrate(ctx *cli.Context) error {
  21. if err := initDB(); err != nil {
  22. return err
  23. }
  24. log.Trace("AppPath: %s", setting.AppPath)
  25. log.Trace("AppWorkPath: %s", setting.AppWorkPath)
  26. log.Trace("Custom path: %s", setting.CustomPath)
  27. log.Trace("Log path: %s", setting.LogRootPath)
  28. setting.InitDBConfig()
  29. if err := models.NewEngine(context.Background(), migrations.Migrate); err != nil {
  30. log.Fatal("Failed to initialize ORM engine: %v", err)
  31. return err
  32. }
  33. return nil
  34. }