fix(billing): pending_checkouts ON DELETE CASCADE (mig 069) — unblock team reap#272
Merged
Merged
Conversation
… team reap 053_pending_checkouts created the team_id FK without ON DELETE CASCADE — the ONLY team-child table missing it. DeleteTeamHard (the e2e-account reap) and the worker team_deletion_executor delete a team with a bare DELETE FROM teams and rely on children cascading, so a team that ever started a checkout (→ a pending_checkouts row) failed: pq: ... violates foreign key constraint "pending_checkouts_team_id_fkey" This surfaced live the moment test-cohort checkout was armed: a cohort Pro upgrade creates a pending_checkouts row, so the reap 503'd (db_failed) and the cohort team LEAKED — breaking the rule-24 'cohort data is always reaped' guarantee. Found by the real test-card payment run. Migration 069 aligns the FK with every other team-child table (ON DELETE CASCADE), idempotent (DROP IF EXISTS + re-ADD). Already applied live; this codifies it. Test: TestDeleteTeamHard_CascadesPendingCheckouts seeds a pending_checkouts row and asserts DeleteTeamHard cascades it instead of erroring. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Found by the live test-card payment run
Driving the real free→Pro test-card flow surfaced a reap failure: the e2e-account reap 503'd (
db_failed) and the cohort team leaked.Root cause
053_pending_checkoutscreatedteam_id UUID NOT NULL REFERENCES teams(id)with noON DELETE CASCADE— the only team-child table missing it (deployments, stacks, api_keys, audit_log, vault, custom_domains, pending_deletions, pending_propagations, … all cascade).DeleteTeamHard(e2e reap) and the workerteam_deletion_executorbothDELETE FROM teamsand rely on children cascading. Arming test-cohort checkout exposed it: a cohort Pro upgrade creates apending_checkoutsrow → reap fails → rule-24 "cohort data is always reaped" broken.Fix
Migration 069 aligns the FK with every other team-child table (
ON DELETE CASCADE), idempotent (DROP IF EXISTS+ re-ADD). Already applied live (verifiedconfdeltype=c+ reap now 200 for a team with apending_checkoutsrow); this migration codifies it so it survives a fresh DB.Test
TestDeleteTeamHard_CascadesPendingCheckoutsseeds apending_checkoutsrow and assertsDeleteTeamHardcascades it instead of erroring on the FK.🤖 Generated with Claude Code