summaryrefslogtreecommitdiff
path: root/db/migrate/20170912113435_clean_stages_statuses_migration.rb
blob: fc091d7894ecbe9beb29d975e31e93609fb38d41 (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
class CleanStagesStatusesMigration < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

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

  def up
    Gitlab::BackgroundMigration.steal('MigrateStageStatus')

    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
  end

  def down
    # noop
  end
end