mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 11:23:36 +08:00
18 lines
438 B
Ruby
18 lines
438 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
class UpdateInvitesRedemptionCount < ActiveRecord::Migration[6.0]
|
||
|
def change
|
||
|
execute <<~SQL
|
||
|
WITH invite_counts AS (
|
||
|
SELECT invite_id, COUNT(*) count
|
||
|
FROM invited_users
|
||
|
GROUP BY invite_id
|
||
|
)
|
||
|
UPDATE invites
|
||
|
SET redemption_count = GREATEST(redemption_count, count)
|
||
|
FROM invite_counts
|
||
|
WHERE invites.id = invite_counts.invite_id
|
||
|
SQL
|
||
|
end
|
||
|
end
|