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

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package cmd
  4. import (
  5. "context"
  6. "code.gitea.io/gitea/models/db"
  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. }
  19. func runMigrate(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 err := db.InitEngineWithMigration(context.Background(), migrations.Migrate); err != nil {
  31. log.Fatal("Failed to initialize ORM engine: %v", err)
  32. return err
  33. }
  34. return nil
  35. }