feat(billing): migration — backfill 500 signupGrant for existing Free orgs#3664
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3664 +/- ##
=======================================
Coverage 89.54% 89.54%
=======================================
Files 138 138
Lines 4733 4733
Branches 1472 1472
=======================================
Hits 4238 4238
Misses 388 388
Partials 107 107
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a billing migration to retroactively apply the Free-tier signup grant to existing organizations, aligning historical Free orgs with the current “grant on signup” behavior in the billing module.
Changes:
- Introduces a new migration that iterates existing
subscriptionson the Free plan and credits asignup_grantledger entry tobillingextrabalances. - Implements idempotency via a synthetic
refId(signup_grant-<orgId>) and a$neguard onledger.refId. - Provides a
down()that removessignup_grantledger entries.
| const SIGNUP_GRANT_AMOUNT = 500; | ||
| const GRANT_SOURCE = 'signup_grant'; |
| // Skip if this org already has a signup_grant entry (idempotent re-run). | ||
| const existing = await extraBalances.findOne( | ||
| { organization: orgId, 'ledger.refId': idempotencyKey }, | ||
| { projection: { _id: 1 } }, | ||
| ); | ||
| if (existing) { skipped += 1; continue; } | ||
|
|
| const result = await db.collection('billingextrabalances').updateMany( | ||
| { 'ledger.source': GRANT_SOURCE }, | ||
| { $pull: { ledger: { source: GRANT_SOURCE } } }, | ||
| ); |
Summary
Implements Task 6 of
docs/superpowers/plans/2026-05-11-n2-free-tier-grant.md— retroactively credits 500 compute (signup_grant) to every existing Free-plan org so they have parity with new signups (N2 one-shot grant).20260511224500-grant-signup-credits-to-existing-free-orgs.jssubscriptions.plan === 'free'ANDstripeStatus !== 'canceled'signup_grant-{orgId}key, partial unique index from PR feat(billing): add creditGrant idempotent method + source field on entries #3662 enforces single-grantdown()removes allsignup_grantledger entries (rollback)Why
WS-B T1 (config) + T2 (creditGrant repo) + T3 (signup hook) + T5 (UI) already shipped. New signups get the 500-compute grant. This migration retro-applies it to free orgs that signed up before the hook landed.
Test plan
Roadmap
[[Trawl — Product — Roadmap]] N2 free-tier-grant Task 6