mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
naive implementation of post_count on categories
This commit is contained in:
14
db/migrate/20131017014509_add_post_count_to_categories.rb
Normal file
14
db/migrate/20131017014509_add_post_count_to_categories.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class AddPostCountToCategories < ActiveRecord::Migration
|
||||
def up
|
||||
add_column :categories, :post_count, :integer, null: false, default: 0
|
||||
execute <<SQL
|
||||
UPDATE categories
|
||||
SET post_count = (SELECT SUM(posts_count) FROM topics
|
||||
WHERE category_id = categories.id AND deleted_at IS NULL)
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :categories, :post_count
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user