summaryrefslogtreecommitdiff
path: root/db/post_migrate/20210722042939_update_issuable_slas_where_issue_closed.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
commitb76ae638462ab0f673e5915986070518dd3f9ad3 (patch)
treebdab0533383b52873be0ec0eb4d3c66598ff8b91 /db/post_migrate/20210722042939_update_issuable_slas_where_issue_closed.rb
parent434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff)
downloadgitlab-ce-b76ae638462ab0f673e5915986070518dd3f9ad3.tar.gz
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
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.rb31
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