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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. setting.InitDBConfig()
  32. if err := db.InitEngineWithMigration(context.Background(), migrations.Migrate); err != nil {
  33. log.Fatal("Failed to initialize ORM engine: %v", err)
  34. return err
  35. }
  36. return nil
  37. }