Skip to content

Instantly share code, notes, and snippets.

@dpickett
Last active August 29, 2015 14:01
Show Gist options
  • Save dpickett/bb1d72b1f0f240aa3703 to your computer and use it in GitHub Desktop.
Save dpickett/bb1d72b1f0f240aa3703 to your computer and use it in GitHub Desktop.
contrived migration
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