summaryrefslogtreecommitdiff
path: root/db/post_migrate/20220524074947_finalize_backfill_null_note_discussion_ids.rb
blob: 45dbc028b18164a906055abd68132496225173fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

class FinalizeBackfillNullNoteDiscussionIds < Gitlab::Database::Migration[2.0]
  MIGRATION = 'BackfillNoteDiscussionId'
  BATCH_SIZE = 10_000

  restrict_gitlab_migration gitlab_schema: :gitlab_main

  disable_ddl_transaction!

  def up
    Gitlab::BackgroundMigration.steal(MIGRATION)

    define_batchable_model('notes').where(discussion_id: nil).each_batch(of: BATCH_SIZE) do |batch|
      range = batch.pick('MIN(id)', 'MAX(id)')

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

  def down
  end
end