code.gitea.io/gitea@v1.21.7/cmd/migrate.go (about)

     1  // Copyright 2018 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package cmd
     5  
     6  import (
     7  	"context"
     8  
     9  	"code.gitea.io/gitea/models/db"
    10  	"code.gitea.io/gitea/models/migrations"
    11  	"code.gitea.io/gitea/modules/log"
    12  	"code.gitea.io/gitea/modules/setting"
    13  
    14  	"github.com/urfave/cli/v2"
    15  )
    16  
    17  // CmdMigrate represents the available migrate sub-command.
    18  var CmdMigrate = &cli.Command{
    19  	Name:        "migrate",
    20  	Usage:       "Migrate the database",
    21  	Description: "This is a command for migrating the database, so that you can run gitea admin create-user before starting the server.",
    22  	Action:      runMigrate,
    23  }
    24  
    25  func runMigrate(ctx *cli.Context) error {
    26  	stdCtx, cancel := installSignals()
    27  	defer cancel()
    28  
    29  	if err := initDB(stdCtx); err != nil {
    30  		return err
    31  	}
    32  
    33  	log.Info("AppPath: %s", setting.AppPath)
    34  	log.Info("AppWorkPath: %s", setting.AppWorkPath)
    35  	log.Info("Custom path: %s", setting.CustomPath)
    36  	log.Info("Log path: %s", setting.Log.RootPath)
    37  	log.Info("Configuration file: %s", setting.CustomConf)
    38  
    39  	if err := db.InitEngineWithMigration(context.Background(), migrations.Migrate); err != nil {
    40  		log.Fatal("Failed to initialize ORM engine: %v", err)
    41  		return err
    42  	}
    43  
    44  	return nil
    45  }