[MM-37987] cmd/mattermost/version: remove store initialization from version cmd (#19364)

* cmd/mattermost/version: remove store initialization from version cmd

* Update cmd/mattermost/commands/db.go

Co-authored-by: Carlos Tadeu Panato Junior <carlos@mattermost.com>

* reflect review comments

* commands/db: fix config store initializer

Co-authored-by: Carlos Tadeu Panato Junior <carlos@mattermost.com>
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2022-02-16 11:48:01 +03:00
коммит произвёл GitHub
родитель 459f54ac9d
Коммит 23ade1d0c0
7 изменённых файлов: 35 добавлений и 33 удалений

Просмотреть файл

@@ -44,12 +44,20 @@ var ResetCmd = &cobra.Command{
RunE: resetCmdF,
}
var MigrateCmd = &cobra.Command{
Use: "migrate",
Short: "Migrate the database if there are any unapplied migrations",
Long: "Run the missing migrations from the migrations table.",
RunE: migrateCmdF,
}
func init() {
ResetCmd.Flags().Bool("confirm", false, "Confirm you really want to delete everything and a DB backup has been performed.")
DbCmd.AddCommand(
InitDbCmd,
ResetCmd,
MigrateCmd,
)
RootCmd.AddCommand(
@@ -113,3 +121,19 @@ func resetCmdF(command *cobra.Command, args []string) error {
return nil
}
func migrateCmdF(command *cobra.Command, args []string) error {
cfgDSN := getConfigDSN(command, config.GetEnvironment())
cfgStore, err := config.NewStoreFromDSN(cfgDSN, true, nil, true)
if err != nil {
return errors.Wrap(err, "failed to load configuration")
}
config := cfgStore.Get()
store := sqlstore.New(config.SqlSettings, nil)
defer store.Close()
CommandPrettyPrintln("Database successfully migrated")
return nil
}

Просмотреть файл

@@ -6,7 +6,6 @@ package commands
import (
"github.com/spf13/cobra"
"github.com/mattermost/mattermost-server/v6/app"
"github.com/mattermost/mattermost-server/v6/model"
)
@@ -18,37 +17,16 @@ var VersionCmd = &cobra.Command{
func init() {
VersionCmd.Flags().Bool("skip-server-start", false, "Skip the server initialization and return the Mattermost version without the DB version.")
VersionCmd.Flags().MarkDeprecated("skip-server-start", "This flag is not necessary anymore and the flag will be removed in the future releases. Consider removing it from your scripts.")
RootCmd.AddCommand(VersionCmd)
}
func versionCmdF(command *cobra.Command, args []string) error {
skipStart, _ := command.Flags().GetBool("skip-server-start")
if skipStart {
printVersionNoDB()
return nil
}
a, err := InitDBCommandContextCobra(command)
if err != nil {
return err
}
defer a.Srv().Shutdown()
printVersion(a)
return nil
}
func printVersion(a *app.App) {
printVersionNoDB()
CommandPrintln("DB Version: " + a.Srv().Store.GetCurrentSchemaVersion())
}
func printVersionNoDB() {
CommandPrintln("Version: " + model.CurrentVersion)
CommandPrintln("Build Number: " + model.BuildNumber)
CommandPrintln("Build Date: " + model.BuildDate)
CommandPrintln("Build Hash: " + model.BuildHash)
CommandPrintln("Build Enterprise Ready: " + model.BuildEnterpriseReady)
return nil
}