debian-mirror-gitlab/scripts/post_deployment_migrations_validator

32 lines
768 B
Text
Raw Normal View History

2022-11-25 23:54:43 +05:30
#!/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!