I have created a migration in a Rails application:
class UpdateDefaultValues < ActiveRecord::Migration[5.2]
def up
OrderType.where(:category =>"reclamation").update_all(:prevent_delivery => false)
InvoiceType.where(:category =>"reclamation").update_all(:send_automatically => true)
end
def down
OrderType.where(:category =>"reclamation").update_all(:prevent_delivery => true)
InvoiceType.where(:category =>"reclamation").update_all(:send_automatically => false)
end
end
Notably, this migration does not change the database schema; it performs data changes only.
I was wondering: Does rails execute the up
and down
methods within SQL transactions automatically, or do I need to wrap the two updates within own transaction, to make sure that the migration will update all or nothing?