Using the gem zero_downtime_migrations
A simple example is adding a migration such as adding a column with a defalut value: zero_downtime_migrations
README#Adding a Column with a Default with default: true
for a :boolean
column:
class AddDefaultToCampaignsTestingZDM < ActiveRecord::Migration
def change
add_column :direct_campaigns, :zero_migration_test, :boolean, default: true
end
end
This throws an error when migrating via:
bundle exec rake db:migrate
If this potentially halts current work and is too frustrating to deal with immediately, there are several ways to ignore a specific migration. Using the safety_assured
block, or method marks code to be ignored, or the shell environment can be used, like SAFETY_ASSURED=1 bundle exec rake db:migrate --trace
. Several more ways detailed here too: Disabling "zero downtime migration" enforcements.