-
-
Notifications
You must be signed in to change notification settings - Fork 10
refactor(billing): planDefinitions array shape — single source of truth (#3560) #3562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
PierreBrisorgueil
merged 2 commits into
master
from
refactor/billing-plan-definitions-array-3560
May 1, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
docs/migrations/2026-05-01-billing-plan-definitions-array.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Migration: billing.planDefinitions array shape (2026-05-01) | ||
|
|
||
| ## Why | ||
|
|
||
| During PR-N6 (#3555), the `enterprise` plan was present in `billing.plans` but missing from `billing.planDefinitions`. This silent divergence would have caused `ensureSeeded()` to skip seeding the enterprise plan, resulting in a `null` return from `getActivePlan('enterprise')` and a 503 for all metered enterprise users. | ||
|
|
||
| The root cause: `plans` (enum array) and `planDefinitions` (definition map) were two separate declarations that had to be kept in sync manually. The fix is to make `planDefinitions` the single source of truth — `plans` is now derived at boot. | ||
|
|
||
| ## Before / After | ||
|
|
||
| **Before (object-keyed — deprecated):** | ||
|
|
||
| ```js | ||
| billing: { | ||
| plans: ['free', 'starter', 'pro', 'enterprise'], // must match planDefinitions keys — drift risk | ||
| planDefinitions: { | ||
| free: { meterQuota: 0, ratios: { default: 1 } }, | ||
| starter: { meterQuota: 50000, ratios: { default: 1 } }, | ||
| pro: { meterQuota: 500000, ratios: { default: 1 } }, | ||
| enterprise: { meterQuota: 2000000, ratios: { default: 1 } }, | ||
| }, | ||
| } | ||
| ``` | ||
|
|
||
| **After (array — canonical):** | ||
|
|
||
| ```js | ||
| billing: { | ||
| // plans: derived at boot from planDefinitions — do NOT declare manually | ||
| planDefinitions: [ | ||
| { planId: 'free', meterQuota: 0, ratios: { default: 1 } }, | ||
| { planId: 'starter', meterQuota: 50000, ratios: { default: 1 } }, | ||
| { planId: 'pro', meterQuota: 500000, ratios: { default: 1 } }, | ||
| { planId: 'enterprise', meterQuota: 2000000, ratios: { default: 1 } }, | ||
| ], | ||
| } | ||
| ``` | ||
|
|
||
| `config.billing.plans` is still available at runtime (derived by `config/index.js`) — `z.enum(config.billing.plans)` and all Zod/Mongoose schemas keep working unchanged. | ||
|
|
||
| ## Downstream migration steps | ||
|
|
||
| For each downstream project that overrides `billing.planDefinitions` (e.g. `modules/billing/config/billing.{project}.config.js`): | ||
|
|
||
| 1. Pull the latest devkit: `npm run update-stack` (or merge the upstream devkit branch). | ||
| 2. Open `modules/billing/config/billing.{project}.config.js`. | ||
| 3. Convert `planDefinitions` from object to array form (see Before/After above). Remove the `plans: [...]` line — leaving it is harmless (the derivation in `config/index.js` runs after deepMerge and overwrites it), but remove it to avoid confusion. | ||
| 4. Run unit tests: `NODE_ENV={project} npm run test:unit -- billing`. | ||
| 5. Smoke test the plans endpoint: `curl https://api.{project}.example.com/api/billing/plans`. | ||
|
|
||
| No database migration is required — the `BillingPlan` collection is unchanged. | ||
|
|
||
| ## Validation | ||
|
|
||
| After migration, confirm: | ||
|
|
||
| - Boot logs show **no** `[billing] planDefinitions object shape is deprecated` warning (shim did not trigger). | ||
| - `NODE_ENV={project} npm run test:unit -- billing` passes. | ||
| - `[billing] Subscription.plan value "..." not in planDefinitions` warning is **absent** in boot logs (no orphaned subscriptions). | ||
|
|
||
| ## Shim removal timeline | ||
|
|
||
| The backward-compat shim in `config/index.js` converts legacy object-keyed `planDefinitions` to array form with a `console.warn`. It will be removed **~2026-07-01**, contingent on: | ||
|
|
||
| - Zero deprecation warnings observed in any downstream prod log for ≥ 30 days. | ||
| - All downstream projects confirmed migrated to array form. | ||
|
|
||
| Track removal in a follow-up issue once all downstreams are migrated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.