discourse/db/post_migrate/20211019152356_populate_pen...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

23 lines
563 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class PopulatePendingPostsCountColumn < ActiveRecord::Migration[6.1]
def up
execute <<~SQL
WITH to_update AS (
SELECT COUNT(id) AS posts, created_by_id
FROM reviewables
WHERE type = 'ReviewableQueuedPost'
AND status = #{ReviewableQueuedPost.statuses[:pending]}
GROUP BY created_by_id
)
UPDATE user_stats
SET pending_posts_count = to_update.posts
FROM to_update
WHERE to_update.created_by_id = user_stats.user_id
SQL
end
def down
end
end