Skip to content

Instantly share code, notes, and snippets.

@cluesque
Forked from betamatt/gist:151370
Created August 12, 2009 14:49
Show Gist options
  • Save cluesque/166542 to your computer and use it in GitHub Desktop.
Save cluesque/166542 to your computer and use it in GitHub Desktop.
# 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