gitea源码

migrate.go 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/modules/log"
  8. "code.gitea.io/gitea/modules/setting"
  9. "code.gitea.io/gitea/services/versioned_migration"
  10. "github.com/urfave/cli/v3"
  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 context.Context, c *cli.Command) error {
  20. if err := initDB(ctx); err != nil {
  21. return err
  22. }
  23. log.Info("AppPath: %s", setting.AppPath)
  24. log.Info("AppWorkPath: %s", setting.AppWorkPath)
  25. log.Info("Custom path: %s", setting.CustomPath)
  26. log.Info("Log path: %s", setting.Log.RootPath)
  27. log.Info("Configuration file: %s", setting.CustomConf)
  28. if err := db.InitEngineWithMigration(context.Background(), versioned_migration.Migrate); err != nil {
  29. log.Fatal("Failed to initialize ORM engine: %v", err)
  30. return err
  31. }
  32. return nil
  33. }