From dd45a1748920a555d107eaf8bfd4219ed2d4f987 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Mon, 11 Dec 2017 11:06:47 +0000 Subject: Improve down step of removing issues.assignee_id column Using update_column_in_batches means that we can chunk the updates. --- db/migrate/20170523073948_remove_assignee_id_from_issue.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'db') 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 -- cgit v1.2.1