summaryrefslogtreecommitdiff
path: root/db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb
blob: 6b326bc0b6930ad123b2a9336aa0385abb391f4e (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
class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers

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

  disable_ddl_transaction!

  class Build < ActiveRecord::Base
    self.table_name = 'ci_builds'
  end

  def up
    Build.find_in_batches(batch_size: BATCH_SIZE).with_index do |builds, batch|
      migrations = builds.map { |build| [MIGRATION, [build.id]] }

      BackgroundMigrationWorker.perform_bulk(*migrations)
    end
  end

  def down
    # noop
  end
end