summaryrefslogtreecommitdiff
path: root/db/post_migrate/20210513163904_cleanup_move_container_registry_enabled_to_project_feature.rb
blob: 665d274a0ee2f06125c20c96f3db3b78009d03b1 (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
32
33
34
35
36
# frozen_string_literal: true

class CleanupMoveContainerRegistryEnabledToProjectFeature < ActiveRecord::Migration[6.0]
  MIGRATION = 'MoveContainerRegistryEnabledToProjectFeature'

  disable_ddl_transaction!

  def up
    Gitlab::BackgroundMigration.steal(MIGRATION)

    bg_migration_job_class = define_background_migration_jobs_class
    bg_migration_job_class.where(class_name: MIGRATION, status: bg_migration_job_class.statuses['pending']).each do |job|
      Gitlab::BackgroundMigration::MoveContainerRegistryEnabledToProjectFeature.new.perform(*job.arguments)
    end

    bg_migration_job_class.where(class_name: MIGRATION).delete_all
  end

  def down
    # no-op
  end

  private

  def define_background_migration_jobs_class
    Class.new(ActiveRecord::Base) do
      self.table_name = 'background_migration_jobs'
      self.inheritance_column = :_type_disabled

      enum status: {
        pending: 0,
        succeeded: 1
      }
    end
  end
end