20170912113435_clean_stages_statuses_migration.rb 570 Bytes
Newer Older
1
class CleanStagesStatusesMigration < ActiveRecord::Migration[4.2]
2 3 4 5 6 7
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

8 9 10 11 12
  class Stage < ActiveRecord::Base
    include ::EachBatch
    self.table_name = 'ci_stages'
  end

13 14
  def up
    Gitlab::BackgroundMigration.steal('MigrateStageStatus')
15 16 17 18 19 20

    Stage.where('status IS NULL').each_batch(of: 50) do |batch|
      range = batch.pluck('MIN(id)', 'MAX(id)').first

      Gitlab::BackgroundMigration::MigrateStageStatus.new.perform(*range)
    end
21 22 23 24 25 26
  end

  def down
    # noop
  end
end