Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20200207185149_schedule_fix_orphan_promoted_issues.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 83ba56501dd400e22e6a627cf8f172fbdf6dc82e (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
28
29
30
31
32
33
34
35
# frozen_string_literal: true

class ScheduleFixOrphanPromotedIssues < ActiveRecord::Migration[5.2]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  BATCH_SIZE = 100
  BACKGROUND_MIGRATION = 'FixOrphanPromotedIssues'.freeze

  disable_ddl_transaction!

  class Note < ActiveRecord::Base
    include EachBatch

    self.table_name = 'notes'

    scope :of_promotion, -> do
      where(noteable_type: 'Issue')
        .where('notes.system IS TRUE')
        .where("notes.note LIKE 'promoted to epic%'")
    end
  end

  def up
    Note.of_promotion.each_batch(of: BATCH_SIZE) do |notes, index|
      jobs = notes.map { |note| [BACKGROUND_MIGRATION, [note.id]] }

      BackgroundMigrationWorker.bulk_perform_async(jobs)
    end
  end

  def down
    # NO OP
  end
end