summaryrefslogtreecommitdiff
path: root/db/post_migrate/20210722042939_update_issuable_slas_where_issue_closed.rb
blob: b611b51e3ffd094513453d988e59c7d11043fffc (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
# frozen_string_literal: true

class UpdateIssuableSlasWhereIssueClosed < ActiveRecord::Migration[6.1]
  ISSUE_CLOSED_STATUS = 2

  class IssuableSla < ActiveRecord::Base
    include EachBatch

    self.table_name = 'issuable_slas'

    belongs_to :issue, class_name: 'Issue'
  end

  class Issue < ActiveRecord::Base
    self.table_name = 'issues'

    has_one :issuable_sla, class_name: 'IssuableSla'
  end

  def up
    IssuableSla.each_batch(of: 50) do |relation|
      relation.joins(:issue)
              .where(issues: { state_id: ISSUE_CLOSED_STATUS } )
              .update_all(issuable_closed: true)
    end
  end

  def down
    # no-op
  end
end