summaryrefslogtreecommitdiff
path: root/db/migrate/20180425131009_assure_commits_count_for_merge_request_diff.rb
blob: 7d38a15b850d119798d31bf1ede4fb46f4d0c4eb (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
class AssureCommitsCountForMergeRequestDiff < ActiveRecord::Migration[4.2]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  class MergeRequestDiff < ActiveRecord::Base
    self.table_name = 'merge_request_diffs'

    include ::EachBatch
  end

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

    MergeRequestDiff.where(commits_count: nil).each_batch(of: 50) do |batch|
      range = batch.pluck('MIN(id)', 'MAX(id)').first

      Gitlab::BackgroundMigration::AddMergeRequestDiffCommitsCount.new.perform(*range)
    end
  end

  def down
    # noop
  end
end