mirror of
https://github.com/discourse/discourse.git
synced 2024-12-30 08:53:54 +08:00
2a4ddc621d
Redeeming email invites did not increase the redemption_count which let those invites in a weird state were they were both pending and redeemed.
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
|