[MM-53840] Add migration workflow (#24211)

Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2023-08-16 10:09:11 +03:00
коммит произвёл GitHub
родитель 0e75982f2b
Коммит 83652aa3c2
8 изменённых файлов: 152 добавлений и 7 удалений

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

@@ -540,7 +540,7 @@ test-data: run-server inject-test-data ## start a local instance and add test da
inject-test-data: # add test data to the local instance.
@if ! ./scripts/wait-for-system-start.sh; then \
make stop; \
make stop-server; \
fi
@echo ServiceSettings.EnableLocalMode must be set to true.
@@ -554,6 +554,8 @@ inject-test-data: # add test data to the local instance.
@echo Login with a regular account username=user-1 password=SampleUs@r-1
@echo ========================================================================
make stop-server
test-mmctl-unit: export MM_SERVER_PATH := $(MM_SERVER_PATH)
test-mmctl-unit: export GOTESTSUM_FORMAT := $(GOTESTSUM_FORMAT)
test-mmctl-unit: export GOTESTSUM_JUNITFILE := $(GOTESTSUM_JUNITFILE)
@@ -811,7 +813,7 @@ ifeq ($(BUILD_ENTERPRISE_READY),true)
endif
mmctl-build: ## Compiles and generates the mmctl binary
go build -trimpath -ldflags '$(LDFLAGS)' -o $(GOBIN) ./cmd/mmctl
go build -trimpath -ldflags '$(LDFLAGS)' -o bin/mmctl ./cmd/mmctl
mmctl-docs: ## Generate the mmctl docs
rm -rf ./cmd/mmctl/docs
@@ -828,3 +830,32 @@ migrations-extract:
@echo Listing migration files
@echo "# Autogenerated file to synchronize migrations sequence in the PR workflow, please do not edit.\n#" > channels/db/migrations/migrations.list
find channels/db/migrations -maxdepth 2 -mindepth 2 | sort >> channels/db/migrations/migrations.list
test-migration:
$(GO) install github.com/mattermost/morph/cmd/morph@latest
# apply postgres migrations to the new db
bin/morph apply up --driver postgres --dsn "${POSTGRES_DSN}" --path ${POSTGRES_MIGRATIONS_PATH} --number -1
# create temporary file for the config
@cp tests/template.load tests/temp.load
# set required values for the pgloader config, these values are read from /build/dotenv/migration.env in the CI
# do for psql credentials
@sed -i'' -e 's|{{ .pg_user }}|${PG_USERNAME}|g' tests/temp.load
@sed -i'' -e 's|{{ .pg_password }}|${PG_PASSWORD}|g' tests/temp.load
@sed -i'' -e 's|{{ .target_schema }}|${PG_SCHEMA}|g' tests/temp.load
# do for mysql credentials
@sed -i'' -e 's|{{ .mysql_user }}|${MYSQL_USERNAME}|g' tests/temp.load
@sed -i'' -e 's|{{ .mysql_password }}|${MYSQL_PASSWORD}|g' tests/temp.load
@sed -i'' -e 's|{{ .source_schema }}|${MYSQL_SCHEMA}|g' tests/temp.load
# run pgloader and save the logs
pgloader tests/temp.load > migration.log
$(GO) install github.com/mattermost/dbcmp/cmd/dbcmp@latest
# compare two database contents
# db_migrations differ due to a typo in the 92. migration name
# for now we exclude plugins such as playbooks and focalboard
# we also exlude systems table temporarily due to adding some keys while running the initial migration
bin/dbcmp --source "${MYSQL_DSN}" --target "${POSTGRES_DSN}" --exclude="db_migrations","ir_","focalboard","systems"