diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-17 15:10:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-17 15:10:08 +0300 |
commit | 8060e5c60901ab0f6b890414dccbdf5d1b95c3ad (patch) | |
tree | fc217fe53f68a45ea225c0d1b966642852d96321 /scripts/post_deployment_migrations_validator | |
parent | b9b58dba70466949d761132d2d96f0f24c0b469c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts/post_deployment_migrations_validator')
-rwxr-xr-x | scripts/post_deployment_migrations_validator | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/scripts/post_deployment_migrations_validator b/scripts/post_deployment_migrations_validator new file mode 100755 index 00000000000..3df2f772197 --- /dev/null +++ b/scripts/post_deployment_migrations_validator @@ -0,0 +1,31 @@ +#!/usr/bin/env ruby + +# frozen_string_literal: true + +require_relative 'migration_schema_validator' + +class PostDeploymentMigrationsValidator < MigrationSchemaValidator + def validate! + if committed_migrations.empty? + puts "\e[32m No migrations found, skipping post-deployment migrations validation\e[0m" + return + end + + rollback_commited_migrations + + run("SKIP_POST_DEPLOYMENT_MIGRATIONS=true scripts/db_tasks db:migrate") + run("scripts/db_tasks db:migrate") + end + + private + + def rollback_commited_migrations + committed_migrations.reverse_each do |filename| + version = find_migration_version(filename) + + run("scripts/db_tasks db:migrate:down VERSION=#{version}") + end + end +end + +PostDeploymentMigrationsValidator.new.validate! |