mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 13:09:33 -06:00
5b51ed3856
This commit promotes all post_deploy migrations which existed in Discourse v3.2.0 (timestamp <= 20240112043325)
23 lines
600 B
Ruby
23 lines
600 B
Ruby
# frozen_string_literal: true
|
|
|
|
class UpdateThreadReplyCounts < ActiveRecord::Migration[7.0]
|
|
def up
|
|
DB.exec <<~SQL
|
|
UPDATE chat_threads threads
|
|
SET replies_count = subquery.replies_count
|
|
FROM (
|
|
SELECT COUNT(*) - 1 AS replies_count, thread_id
|
|
FROM chat_messages
|
|
WHERE chat_messages.deleted_at IS NULL AND thread_id IS NOT NULL
|
|
GROUP BY thread_id
|
|
) subquery
|
|
WHERE threads.id = subquery.thread_id
|
|
AND subquery.replies_count != threads.replies_count
|
|
SQL
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration
|
|
end
|
|
end
|