1 class TopicsCacheLastRepliedUser < ActiveRecord::Migration
2 class Post < ActiveRecord::Base; end
3 class Topic < ActiveRecord::Base
7 add_column "topics", "replied_by", :integer
8 add_column "topics", "last_post_id", :integer
9 Topic.find(:all).each do |topic|
10 next if topic.posts.count.zero?
11 topic.replied_by = topic.posts.last.user_id
12 topic.last_post_id = topic.posts.last.id
18 remove_column "topics", "replied_by"
19 remove_column "topics", "last_post_id"