educoder/db/migrate/20190321081720_add_praises_...

12 lines
371 B

6 years ago
class AddPraisesCountToMessages < ActiveRecord::Migration[5.2]
def change
add_column :messages, :praises_count, :integer, :default => 0
Message.find_each do |msg|
total_count = msg.praise_treads.liker.count
puts "====> set message's praises_count to #{total_count}"
msg.update_column(:praises_count, total_count)
end
end
end