Add the missing foreign key that documents a relationship
A relationship the code assumes and the database never declared, made explicit once the rows with no match are fixed.
The ticket
Add the foreign key constraint for a relationship the code already assumes.
Acceptance criteria
- Violating rows are reported and resolved before the constraint is added
- The constraint is added without an unacceptable lock
- The delete behaviour is chosen deliberately and stated
- A test asserts the constraint rejects an orphan
What lands as proof
A count of violating rows before the fix, and a test proving the constraint now refuses one.
Why teams defer it
- The application enforces it well enough, so the constraint feels redundant until a bug writes an orphan.
- There are almost always existing orphans, and deciding what to do with them is a data question rather than a schema one.
Questions
- What does the agent actually change?
- The ticket is scoped to one outcome: add the foreign key constraint for a relationship the code already assumes. Work that serves that outcome is in scope, and anything outside it is left for a separate ticket, so the pull request stays reviewable.
- How do I know the work is done?
- The pull request carries the evidence, not only the diff. Here that means violating rows reported and resolved before the constraint lands, so a reviewer can confirm the result without reproducing the work locally.
- How much oversight does this need?
- The run stops once the plan is written. Somebody reads the approach and approves it before any code exists, which is the cheapest moment to redirect the work.