summaryrefslogtreecommitdiff
path: root/db/post_migrate/20190926180443_schedule_epic_issues_after_epics_move.rb
blob: 86fe0f26681da90c69b81f410fac7934dd530749 (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
# frozen_string_literal: true

# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.

class ScheduleEpicIssuesAfterEpicsMove < ActiveRecord::Migration[5.2]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  INTERVAL = 5.minutes.to_i
  BATCH_SIZE = 100
  MIGRATION = 'MoveEpicIssuesAfterEpics'

  disable_ddl_transaction!

  class Epic < ActiveRecord::Base
    self.table_name = 'epics'

    include ::EachBatch
  end

  def up
    return unless ::Gitlab.ee?

    Epic.each_batch(of: BATCH_SIZE) do |batch, index|
      range = batch.pluck('MIN(id)', 'MAX(id)').first
      delay = index * INTERVAL
      BackgroundMigrationWorker.perform_in(delay, MIGRATION, *range)
    end
  end

  def down
    # no need
  end
end