diff options
author | Robert Speicher <rspeicher@gmail.com> | 2016-03-29 01:03:29 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-03-29 01:03:29 +0300 |
commit | 47a539dfd7733968b25b73e6b8b61348926207af (patch) | |
tree | c84a4cd61430ec48426098364f7260892f6b3024 /db/migrate/20130220125544_convert_merge_status_in_merge_request.rb | |
parent | d73e1288595ef673b2d9c3024d7fe3909dac7184 (diff) |
Use raw SQL instead of Rails models in migrations where appropriate
Closes #14694.
Diffstat (limited to 'db/migrate/20130220125544_convert_merge_status_in_merge_request.rb')
-rw-r--r-- | db/migrate/20130220125544_convert_merge_status_in_merge_request.rb | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/db/migrate/20130220125544_convert_merge_status_in_merge_request.rb b/db/migrate/20130220125544_convert_merge_status_in_merge_request.rb index b310b35e373..1c758c56ffe 100644 --- a/db/migrate/20130220125544_convert_merge_status_in_merge_request.rb +++ b/db/migrate/20130220125544_convert_merge_status_in_merge_request.rb @@ -1,17 +1,19 @@ class ConvertMergeStatusInMergeRequest < ActiveRecord::Migration def up - MergeRequest.transaction do - MergeRequest.where(merge_status: 1).update_all("new_merge_status = 'unchecked'") - MergeRequest.where(merge_status: 2).update_all("new_merge_status = 'can_be_merged'") - MergeRequest.where(merge_status: 3).update_all("new_merge_status = 'cannot_be_merged'") - end + execute "UPDATE #{table_name} SET new_merge_status = 'unchecked' WHERE merge_status = 1" + execute "UPDATE #{table_name} SET new_merge_status = 'can_be_merged' WHERE merge_status = 2" + execute "UPDATE #{table_name} SET new_merge_status = 'cannot_be_merged' WHERE merge_status = 3" end def down - MergeRequest.transaction do - MergeRequest.where(new_merge_status: :unchecked).update_all("merge_status = 1") - MergeRequest.where(new_merge_status: :can_be_merged).update_all("merge_status = 2") - MergeRequest.where(new_merge_status: :cannot_be_merged).update_all("merge_status = 3") - end + execute "UPDATE #{table_name} SET merge_status = 1 WHERE new_merge_status = 'unchecked'" + execute "UPDATE #{table_name} SET merge_status = 2 WHERE new_merge_status = 'can_be_merged'" + execute "UPDATE #{table_name} SET merge_status = 3 WHERE new_merge_status = 'cannot_be_merged'" + end + + private + + def table_name + MergeRequest.table_name end end |