fix(db): truncate downstream tables before services dedup to avoid FK violation (GRO-365) #197
Reference in New Issue
Block a user
Delete Branch "fix/gro-360-yq-compound-assignment"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
TRUNCATE appointments, invoices, invoice_line_items, invoice_tip_splits, grooming_visit_logs CASCADEbefore services upsert to prevent FK violations from stale appointmentsON CONFLICTtarget fromidtonamewith a unique constraint onnamein the schemaWhy this fixes both issues
GRO-365 (FK violation): The old dedup DELETE could delete services referenced by appointments from prior seed runs, causing
RESTRICTFK violations. The TRUNCATE clears downstream tables first, so no service referenced by appointments is ever deleted.GRO-301 (duplicate services): The old dedup used
MIN(id) per namewhich could delete the wrong service row (e.g., if IDs weren't in name order). Subsequent INSERTs would then create duplicates. By removing dedup and usingON CONFLICT (name) DO UPDATEwith a unique constraint onname, each service name is unique by construction — first run inserts, subsequent runs update.Files changed
packages/db/src/seed.ts— remove dedup DELETE, useON CONFLICT (name), keep TRUNCATEpackages/db/src/schema.ts— add.unique()toservices.nameTest plan
/admin/services/admin/bookservice selectioncc @cpfarhood
🤖 Generated with Claude Code
QA Review: GRO-366 ✅
Verified the TRUNCATE change in (line 427):
CI Status (all passing):
Branch protection requires 2 approvals (QA + CTO). This is my QA approval. Handing off to CTO for final review and merge.
QA Review: GRO-366
Verified the TRUNCATE change in seed.ts line 427. Fix is minimal and targeted.
CI Status (all passing): Lint, Test, Build, E2E Tests — all SUCCESS.
This is QA approval. Branch protection requires 2 approvals (QA + CTO). Handing off to CTO.
Deployed to groombook-dev
Images:
pr-197URL: https://dev.groombook.farh.net
Ready for UAT validation.
CTO Approval
Fix is correct and minimal:
All CI checks green. QA approved. Ship it.
QA Approval: GRO-368 ✅
PR #197 is merged and all CI checks pass. Verified:
Staff FK violation was addressed in PR #199 (GRO-369) — also merged.
All acceptance criteria met. Branch protection: 2 approvals (QA + CTO) obtained. Handoff to CTO.