[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 удалений

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

@@ -398,7 +398,7 @@ jobs:
-v ~/mattermost:/mattermost \
-w /mattermost/mattermost-server \
mattermost/mattermost-build-server:20210810_golang-1.16.7 \
bash -c "ulimit -n 8096; make ARGS='version' run-cli && make MM_SQLSETTINGS_DATASOURCE='postgres://mmuser:mostest@postgres:5432/latest?sslmode=disable&connect_timeout=10' ARGS='version' run-cli"
bash -c "ulimit -n 8096; make ARGS='db migrate' run-cli && make MM_SQLSETTINGS_DATASOURCE='postgres://mmuser:mostest@postgres:5432/latest?sslmode=disable&connect_timeout=10' ARGS='db migrate' run-cli"
echo "Generating dump"
docker-compose --no-ansi exec -T postgres pg_dump --schema-only -d migrated -U mmuser > migrated.sql
@@ -427,7 +427,7 @@ jobs:
-v ~/mattermost:/mattermost \
-w /mattermost/mattermost-server \
mattermost/mattermost-build-server:20210810_golang-1.16.7 \
bash -c "ulimit -n 8096; make ARGS='version' run-cli && make MM_SQLSETTINGS_DATASOURCE='mmuser:mostest@tcp(mysql:3306)/latest?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s' ARGS='version' run-cli"
bash -c "ulimit -n 8096; make ARGS='db migrate' run-cli && make MM_SQLSETTINGS_DATASOURCE='mmuser:mostest@tcp(mysql:3306)/latest?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s' ARGS='db migrate' run-cli"
echo "Generating dump"
docker-compose --no-ansi exec -T mysql mysqldump --skip-opt --no-data --compact -u root -pmostest migrated > migrated.sql

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

@@ -34,7 +34,7 @@ docker run -d -it --rm --name "$CONTAINER_SERVER" --net $DOCKER_NETWORK \
-v "$CI_PROJECT_DIR":/mattermost-server \
-w /mattermost-server \
$IMAGE_BUILD_SERVER \
bash -c "ulimit -n 8096; make ARGS='version' run-cli && make MM_SQLSETTINGS_DATASOURCE='mmuser:mostest@tcp(mysql:3306)/latest?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s' ARGS='version' run-cli"
bash -c "ulimit -n 8096; make ARGS='db migrate' run-cli && make MM_SQLSETTINGS_DATASOURCE='mmuser:mostest@tcp(mysql:3306)/latest?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s' ARGS='db migrate' run-cli"
mkdir -p logs
docker-compose logs --tail="all" -t --no-color > logs/docker-compose_logs_$COMPOSE_PROJECT_NAME
docker logs -f $CONTAINER_SERVER

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

@@ -33,7 +33,7 @@ docker run -d -it --rm --name $CONTAINER_SERVER --net $DOCKER_NETWORK \
-v "$CI_PROJECT_DIR":/mattermost-server \
-w /mattermost-server \
$IMAGE_BUILD_SERVER \
bash -c "ulimit -n 8096; make ARGS='version' run-cli && make MM_SQLSETTINGS_DATASOURCE='postgres://mmuser:mostest@postgres:5432/latest?sslmode=disable&connect_timeout=10' ARGS='version' run-cli"
bash -c "ulimit -n 8096; make ARGS='db migrate' run-cli && make MM_SQLSETTINGS_DATASOURCE='postgres://mmuser:mostest@postgres:5432/latest?sslmode=disable&connect_timeout=10' ARGS='db migrate' run-cli"
mkdir -p logs
docker-compose logs --tail="all" -t --no-color > logs/docker-compose_logs_$COMPOSE_PROJECT_NAME
docker logs -f $CONTAINER_SERVER

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

@@ -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
}

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

@@ -18,7 +18,7 @@ cat config/config.json | \
jq '.SqlSettings.DriverName = "mysql"' > $TMPDIR/config.json
echo "Running the migration"
make ARGS="version --config $TMPDIR/config.json" run-cli
make ARGS="db migrate --config $TMPDIR/config.json" run-cli
echo "Setting up config for fresh db setup"
cat config/config.json | \
@@ -26,7 +26,7 @@ cat config/config.json | \
jq '.SqlSettings.DriverName = "mysql"' > $TMPDIR/config.json
echo "Setting up fresh db"
make ARGS="version --config $TMPDIR/config.json" run-cli
make ARGS="db migrate --config $TMPDIR/config.json" run-cli
if [ "$SCHEMA_VERSION" == "5.0.0" ]; then
for i in "ChannelMembers SchemeGuest" "ChannelMembers MsgCountRoot" "ChannelMembers MentionCountRoot" "Channels TotalMsgCountRoot"; do

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

@@ -18,7 +18,7 @@ cat config/config.json | \
jq '.SqlSettings.DriverName = "postgres"' > $TMPDIR/config.json
echo "Running the migration"
make ARGS="version --config $TMPDIR/config.json" run-cli
make ARGS="db migrate --config $TMPDIR/config.json" run-cli
echo "Setting up config for fresh db setup"
cat config/config.json | \
@@ -26,7 +26,7 @@ cat config/config.json | \
jq '.SqlSettings.DriverName = "postgres"' > $TMPDIR/config.json
echo "Setting up fresh db"
make ARGS="version --config $TMPDIR/config.json" run-cli
make ARGS="db migrate --config $TMPDIR/config.json" run-cli
if [ "$SCHEMA_VERSION" == "5.0.0" ]; then
for i in "ChannelMembers MentionCountRoot" "ChannelMembers MsgCountRoot" "Channels TotalMsgCountRoot"; do