feat(contributors): add manual tier upgrade for enrolled champions#3121
feat(contributors): add manual tier upgrade for enrolled champions#3121bturcotte520 wants to merge 2 commits intomainfrom
Conversation
| // Prefer the explicit membership link over the email-derived match, same as enrollContributorChampion. | ||
| const linkedKiloUserId = row.linkedKiloUserId ?? row.linkedUserId; | ||
|
|
||
| const creditGranted = await db.transaction(async tx => { |
There was a problem hiding this comment.
WARNING: Concurrent upgrades can double-grant top-up credits
The current tier and credit differential are computed before the transaction acquires the FOR UPDATE lock. If two admins submit the same upgrade concurrently, both requests can read the old tier, then serialize at this lock and each grant the same differential. Re-read the membership/current tier after acquiring the lock (or condition the update on the old tier) before computing/granting the top-up.
| counts_as_selfservice: false, | ||
| dbOrTx: tx, | ||
| }); | ||
| granted = result.success; |
There was a problem hiding this comment.
WARNING: Successful upgrade top-ups do not advance the grant timestamp
When a contributor tier with no prior credits, such as contributor, is manually upgraded and this call grants the immediate top-up, credits_last_granted_at stays NULL. For memberships with linked_kilo_user_id set, the next credit refresh sees the row as due immediately and can grant the new monthly amount again. Mirror enrollment by setting credits_last_granted_at when the top-up succeeds.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
Reviewed by gpt-5.5-2026-04-23 · 416,008 tokens |
…set on tier upgrade
Allow existing champions to be upgraded