`remove_column` triggers check even when wrapped in `safety_assured`
brevio-nicolay opened this issue · 4 comments
brevio-nicolay commented
Hello,
First of all, thank you very much for the excellent library.
Gem version: 0.19.1
Rails version: 7.0.4
class User < ApplicationRecord
self.ignored_columns += ['name', 'email_address']
end
class RemoveOldColumns < ActiveRecord::Migration[7.0]
def change
safety_assured { remove_columns :users, :name, :email_address }
end
end
Triggers:
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
=== Dangerous operation detected #strong_migrations ===
Active Record caches database columns at runtime, so if you drop a column, it can cause exceptions until your app reboots.
A safer approach is to:
1. Ignore the column:
class User < ApplicationRecord
self.ignored_columns += ["name", "email_address"]
end
2. Deploy
3. Wrap column removing in a safety_assured { ... } block
class RemoveUnusedColumns < ActiveRecord::Migration[7.0]
def change
safety_assured { remove_columns :users, :name, :email_address }
end
end
4. Remove column ignoring from step 1
5. Deploy
For more details, see https://github.com/fatkodima/online_migrations#removing-a-column
I have already completed steps (1-3), but when I try to run the migration, this errors keeps stopping me.
fatkodima commented
Dangerous operation detected #strong_migrations
Not the right gem I think 😅
fatkodima commented
Do you use both gems?
brevio-nicolay commented
@fatkodima oh my, you're quite right. Somehow they both got added to the Gemfile! Sorry for the trouble, and thanks again for the excellent work 👍
fatkodima commented
Thank you for kind words and using it! ❤️