d578482e3b
it would be nice to use AR's built-in counter cache, but the comments count has to reflect something custom so stick with what was there
26 lines
571 B
Ruby
26 lines
571 B
Ruby
class MoveCommentCountsToStory < ActiveRecord::Migration
|
|
def up
|
|
add_column :stories, :comments_count, :integer, :default => 0,
|
|
:null => false
|
|
|
|
Keystore.transaction do
|
|
Story.lock(true).select(:id).each do |s|
|
|
s.update_comments_count!
|
|
end
|
|
|
|
Keystore.where(
|
|
Keystore.arel_table[:key].matches("story:%:comment_count")).delete_all
|
|
end
|
|
end
|
|
|
|
def down
|
|
Keystore.transaction do
|
|
Story.select(:id).each do |s|
|
|
s.update_comments_count!
|
|
end
|
|
end
|
|
|
|
remove_column :stories, :comments_count
|
|
end
|
|
end
|