summaryrefslogtreecommitdiff
path: root/db/post_migrate/20180702120647_enqueue_fix_cross_project_label_links.rb
blob: 59aa41adedee01a9aa404416461800ba19ab8fd5 (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
class EnqueueFixCrossProjectLabelLinks < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  BATCH_SIZE = 100
  MIGRATION = 'FixCrossProjectLabelLinks'
  DELAY_INTERVAL = 5.minutes

  disable_ddl_transaction!

  class Label < ActiveRecord::Base
    self.table_name = 'labels'
  end

  class Namespace < ActiveRecord::Base
    self.table_name = 'namespaces'

    include ::EachBatch

    default_scope { where(type: 'Group', id: Label.where(type: 'GroupLabel').select('distinct group_id')) }
  end

  def up
    queue_background_migration_jobs_by_range_at_intervals(Namespace, MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE)
  end

  def down
    # noop
  end
end