-
-
Save cluesque/166542 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A migration that will continue to work after refactoring | |
class FutureProofMigration < ActiveRecord::Migration | |
# Redefine models used in the migration as empty inner classes. This removes all validations and magic. | |
class Model < ActiveRecord::Base; end | |
# Either don't rely on associations or declare them as referring to the new inner class | |
class DependentModel < ActiveRecord::Base | |
belongs_to :model, :class_name => "FutureProofMigration::Model" | |
end | |
def up | |
# Can safely use model class to perform transformations without dropping to sql. Model class may be removed or refactored without breaking this migration | |
Model.update_all ... blah blah... | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment