Welcome to mirror list, hosted at ThFree Co, Russian Federation.

post_deployment_migrations_validator « scripts - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3df2f772197bdc7c016dc9b22391ef834b658dcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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!