diff options
author | Sean McGivern <sean@gitlab.com> | 2017-12-11 14:06:47 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2017-12-11 14:06:47 +0300 |
commit | dd45a1748920a555d107eaf8bfd4219ed2d4f987 (patch) | |
tree | 477e5ea7937d83014f7bf1f11cff69b0adec74c5 /db | |
parent | 43442be4e594113913206c0739c031189ce5b70d (diff) |
Improve down step of removing issues.assignee_id column
Using update_column_in_batches means that we can chunk the updates.
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20170523073948_remove_assignee_id_from_issue.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/db/migrate/20170523073948_remove_assignee_id_from_issue.rb b/db/migrate/20170523073948_remove_assignee_id_from_issue.rb index 6fe2bb9c770..91b04023fc2 100644 --- a/db/migrate/20170523073948_remove_assignee_id_from_issue.rb +++ b/db/migrate/20170523073948_remove_assignee_id_from_issue.rb @@ -25,6 +25,12 @@ class RemoveAssigneeIdFromIssue < ActiveRecord::Migration # comments: disable_ddl_transaction! + class Issue < ActiveRecord::Base + self.table_name = 'issues' + + include ::EachBatch + end + def up remove_column :issues, :assignee_id end @@ -33,6 +39,8 @@ class RemoveAssigneeIdFromIssue < ActiveRecord::Migration add_column :issues, :assignee_id, :integer add_concurrent_index :issues, :assignee_id - execute('UPDATE issues SET assignee_id = (SELECT user_id FROM issue_assignees WHERE issue_assignees.issue_id = issues.id LIMIT 1)') + update_value = Arel.sql('(SELECT user_id FROM issue_assignees WHERE issue_assignees.issue_id = issues.id LIMIT 1)') + + update_column_in_batches(:issues, :assignee_id, update_value) end end |