Skip to content

feat(billing): migration — backfill 500 signupGrant for existing Free orgs#3664

Merged
PierreBrisorgueil merged 1 commit into
masterfrom
feat-billing-grant-backfill
May 12, 2026
Merged

feat(billing): migration — backfill 500 signupGrant for existing Free orgs#3664
PierreBrisorgueil merged 1 commit into
masterfrom
feat-billing-grant-backfill

Conversation

@PierreBrisorgueil
Copy link
Copy Markdown
Contributor

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).

  • Migration 20260511224500-grant-signup-credits-to-existing-free-orgs.js
  • Filter : subscriptions.plan === 'free' AND stripeStatus !== 'canceled'
  • Idempotency : signup_grant-{orgId} key, partial unique index from PR feat(billing): add creditGrant idempotent method + source field on entries #3662 enforces single-grant
  • Re-run safe : second invocation skips all already-granted orgs
  • down() removes all signup_grant ledger 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

  • Dry-run + idempotency check locally
  • Post-merge on devkit-derived pods : migration runs on boot (logs grep `migration|grant-backfill`)
  • trawl_node side : WS-B T7 propagation PR brings this migration into trawl_node

Roadmap

[[Trawl — Product — Roadmap]] N2 free-tier-grant Task 6

Copilot AI review requested due to automatic review settings May 11, 2026 20:53
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Warning

Rate limit exceeded

@PierreBrisorgueil has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 23 minutes and 8 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9e8a3b5c-c5c5-47aa-8f2d-ac63a0879f52

📥 Commits

Reviewing files that changed from the base of the PR and between 3a3ca09 and e762b65.

📒 Files selected for processing (1)
  • modules/billing/migrations/20260511224500-grant-signup-credits-to-existing-free-orgs.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat-billing-grant-backfill

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.54%. Comparing base (3a3ca09) to head (e762b65).

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           
Flag Coverage Δ
integration 59.83% <ø> (ø)
unit 64.96% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3a3ca09...e762b65. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 subscriptions on the Free plan and credits a signup_grant ledger entry to billingextrabalances.
  • Implements idempotency via a synthetic refId (signup_grant-<orgId>) and a $ne guard on ledger.refId.
  • Provides a down() that removes signup_grant ledger entries.

Comment on lines +22 to +23
const SIGNUP_GRANT_AMOUNT = 500;
const GRANT_SOURCE = 'signup_grant';
Comment on lines +47 to +53
// 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; }

Comment on lines +110 to +113
const result = await db.collection('billingextrabalances').updateMany(
{ 'ledger.source': GRANT_SOURCE },
{ $pull: { ledger: { source: GRANT_SOURCE } } },
);
@PierreBrisorgueil PierreBrisorgueil merged commit cf6ea66 into master May 12, 2026
11 checks passed
@PierreBrisorgueil PierreBrisorgueil deleted the feat-billing-grant-backfill branch May 12, 2026 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants