Last active
August 29, 2015 14:01
-
-
Save dpickett/bb1d72b1f0f240aa3703 to your computer and use it in GitHub Desktop.
contrived migration
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
class UpdatePosts < ActiveRecord::Migration | |
class Post < ActiveRecord::Base | |
has_many :comments | |
end | |
class Comment < ActiveRecord::Base | |
belongs_to :post | |
end | |
def change | |
add_column :comments, :provider, :string | |
#updates comment provider | |
Post.where("created_at > :boundary", boundary: 7.months.ago).find_each do |post| | |
post.comments.find_each do |comment| | |
comment.provider = 'disqus' | |
comment.save! | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment