diff options
Diffstat (limited to 'db/post_migrate/20210722042939_update_issuable_slas_where_issue_closed.rb')
-rw-r--r-- | db/post_migrate/20210722042939_update_issuable_slas_where_issue_closed.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/db/post_migrate/20210722042939_update_issuable_slas_where_issue_closed.rb b/db/post_migrate/20210722042939_update_issuable_slas_where_issue_closed.rb new file mode 100644 index 00000000000..b611b51e3ff --- /dev/null +++ b/db/post_migrate/20210722042939_update_issuable_slas_where_issue_closed.rb @@ -0,0 +1,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 |