Skip to content

Instantly share code, notes, and snippets.

@Kalimaha
Last active July 21, 2020 01:43
Show Gist options
  • Save Kalimaha/45f970a0b435d00176ca645078ff5b02 to your computer and use it in GitHub Desktop.
Save Kalimaha/45f970a0b435d00176ca645078ff5b02 to your computer and use it in GitHub Desktop.
Zero downtime migration
################################################################################
# Please Note: this version requires https://github.com/khiav223577/in_batches #
################################################################################
class AddLifecycleWebPushPermittedToUsers < ActiveRecord::Migration
disable_ddl_transaction!
def up
ActiveRecord::Base.transaction do
add_column :users, :lifecycle_web_push_permitted, :boolean, default: nil
execute('ALTER TABLE users ALTER COLUMN lifecycle_web_push_permitted SET DEFAULT false')
end
User.unscoped.in_batches.update_all(lifecycle_web_push_permitted: false)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment