mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Add migration to set correct redemption_count (#12491)
Redeeming email invites did not increase the redemption_count which let those invites in a weird state were they were both pending and redeemed.
This commit is contained in:
17
db/migrate/20210323142518_update_invites_redemption_count.rb
Normal file
17
db/migrate/20210323142518_update_invites_redemption_count.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user