Created
April 25, 2012 17:12
-
-
Save garethrees/2491384 to your computer and use it in GitHub Desktop.
Touching data in migrations
This file contains hidden or 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
| $ git clone my_repo && cd my_repo | |
| $ bundle install | |
| $ rake db:create | |
| $ rake db:create | |
| => Oh no! I can't build the db because I don't have any instances of SomeModel. Useless! |
This file contains hidden or 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
| class SomeMigration < ActiveRecord::Migration | |
| def self.up | |
| add_column :some_models, :last_email_sent_at, :datetime | |
| SomeModel.all.each do |member| | |
| member.last_email_sent_at = Time.now | |
| member.current_email_sent_at = Time.now | |
| member.save false | |
| end | |
| end | |
| def self.down | |
| # ... | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment