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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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/db"
  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. stdCtx, cancel := installSignals()
  22. defer cancel()
  23. if err := initDB(stdCtx); err != nil {
  24. return err
  25. }
  26. log.Info("AppPath: %s", setting.AppPath)
  27. log.Info("AppWorkPath: %s", setting.AppWorkPath)
  28. log.Info("Custom path: %s", setting.CustomPath)
  29. log.Info("Log path: %s", setting.LogRootPath)
  30. log.Info("Configuration file: %s", setting.CustomConf)
  31. if err := db.InitEngineWithMigration(context.Background(), migrations.Migrate); err != nil {
  32. log.Fatal("Failed to initialize ORM engine: %v", err)
  33. return err
  34. }
  35. return nil
  36. }