summaryrefslogtreecommitdiff
path: root/db/post_migrate/20180420080616_schedule_stages_index_migration.rb
blob: eb82f098639fc0add4d4839e5bd5e32d1826f709 (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
class ScheduleStagesIndexMigration < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  MIGRATION = 'MigrateStageIndex'.freeze
  BATCH_SIZE = 10000

  disable_ddl_transaction!

  class Stage < ActiveRecord::Base
    include EachBatch
    self.table_name = 'ci_stages'
  end

  def up
    disable_statement_timeout do
      Stage.all.tap do |relation|
        queue_background_migration_jobs_by_range_at_intervals(relation,
                                                              MIGRATION,
                                                              5.minutes,
                                                              batch_size: BATCH_SIZE)
      end
    end
  end

  def down
    # noop
  end
end