Skip to content

Instantly share code, notes, and snippets.

@garethrees
Created April 25, 2012 17:12
Show Gist options
  • Select an option

  • Save garethrees/2491384 to your computer and use it in GitHub Desktop.

Select an option

Save garethrees/2491384 to your computer and use it in GitHub Desktop.
Touching data in migrations
$ 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!
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