2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-30 23:06:56 -05:00
|
|
|
class AddBookmarkCountToPosts < ActiveRecord::Migration[4.2]
|
2013-02-05 13:16:51 -06:00
|
|
|
def change
|
|
|
|
add_column :posts, :bookmark_count, :integer, default: 0, null: false
|
|
|
|
add_column :forum_threads, :bookmark_count, :integer, default: 0, null: false
|
|
|
|
add_column :forum_threads, :star_count, :integer, default: 0, null: false
|
|
|
|
|
2013-02-25 10:42:20 -06:00
|
|
|
execute "UPDATE posts SET bookmark_count = (SELECT COUNT(*)
|
|
|
|
FROM bookmarks
|
2013-02-05 13:16:51 -06:00
|
|
|
WHERE post_number = posts.post_number AND forum_thread_id = posts.forum_thread_id)"
|
|
|
|
|
2013-02-25 10:42:20 -06:00
|
|
|
execute "UPDATE forum_threads SET bookmark_count = (SELECT COUNT(*)
|
|
|
|
FROM bookmarks
|
2013-02-05 13:16:51 -06:00
|
|
|
WHERE forum_thread_id = forum_threads.id)"
|
|
|
|
|
2013-02-25 10:42:20 -06:00
|
|
|
execute "UPDATE forum_threads SET star_count = (SELECT COUNT(*)
|
|
|
|
FROM forum_thread_users
|
2013-02-05 13:16:51 -06:00
|
|
|
WHERE forum_thread_id = forum_threads.id AND starred = true)"
|
|
|
|
end
|
|
|
|
end
|