So migrations look like this nowadays:
class MyMigration < ActiveRecord::Migration def change create_table :my_table ... end end
To my surprise, the following actually works too!
class MyMigration < ActiveRecord::Migration create_table :my_table ... end
This was a production bug at my company because people make mistakes and there were no automated tools to catch this error. It leads to inconsistent behavior because
- It only gets run at the class load time
- It can’t be rolled back
After some researching, I found that this was the way to do migrations < Rails 3.1. And on Rails 3.1 we got instance method support: converted migrations to support instance methods · rails/rails@8b2f801 · GitHub but class methods were not deprecated.
My question is: what’s the best way to prevent this error from happening?
- Deprecate class method support in future Rails?
- Some custom rubocop rule?
- Some kind of automated test?