Conversation
## Context PR 1 of the catalog-plans split (Dive-In 6): the shared plan ecosystem — coupon targets, plan taxes and entitlements — must be able to point at a catalog plan, not only a legacy plan. This is additive; existing rows keep their plan_id. ## Description Add a nullable catalog_plan_id (+ index + not-valid-then-validated foreign key) to coupon_targets, plans_taxes and entitlement_entitlements, the rate_phase XOR pattern. plans_taxes.plan_id becomes nullable and gains a unique (catalog_plan_id, tax_id) index mirroring the legacy one; entitlements gain a unique (feature, catalog_plan_id) index and their exactly-one-parent check now counts plan, catalog_plan and subscription. Each model validates that it references a single plan (or exactly one parent), and the factories gain catalog-plan variants.
Contributor
|
Automated pre-review (advisory, not a required check) — verdict: HOLD · CI green HOLD —
|
## Context Making plans_taxes.plan_id nullable dropped its database-enforced guarantee that a tax always has a plan, leaving only the model validation — which direct or bulk writes bypass. ## Description Add a check constraint requiring exactly one of plan_id and catalog_plan_id on plans_taxes (not valid, then validated in the follow-up migration), matching the entitlement parent check. Cover it with specs that bypass model validation and prove the database rejects a row with neither or both parents.
Contributor
|
Automated pre-review (advisory, not a required check) — verdict: HOLD · CI green HOLD: The new foreign keys are only wired from the join records, leaving
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this is
The shared plan ecosystem — coupon targets, plan taxes, entitlements — must be able to point at a catalog plan, not only a legacy
Plan. Additive: existing rows keep theirplan_id.Changes
Nullable
catalog_plan_id(+ index + a NOT VALID → validated FK) added tocoupon_targets,plans_taxes,entitlement_entitlements— therate_phaseXOR pattern, real Postgres FKs.plan_idrelaxed to nullable; unique(catalog_plan_id, tax_id)index mirroring the legacy(plan_id, tax_id)one (also serves the FK lookup, so no standalone column index). Model validates exactly one of plan / catalog_plan.(entitlement_feature_id, catalog_plan_id)index mirroring the plan one; the DBexactly_one_parentcheck swapped fromplan XOR subscriptiontonum_nonnulls(plan, catalog_plan, subscription) = 1, and the model validation counts all three.