fix(db): seed staff_id FK fix (GRO-369) #199

Merged
groombook-engineer[bot] merged 5 commits from fix/gro-369-staff-id-fk into main 2026-04-01 14:19:49 +00:00
groombook-engineer[bot] commented 2026-04-01 13:48:24 +00:00 (Migrated from github.com)

Summary

  • Move TRUNCATE statement before the staff upsert block so downstream FK references (appointments, invoices, etc.) are cleared before staff IDs are re-upserted
  • Add id: s.id to the staff upsert onConflictDoUpdate set clause so re-seeded rows get their IDs overwritten to match the deterministic PRNG values
  • Prevents appointments insert from referencing staff IDs that don't exist in the DB after a re-seed

Root Cause

On re-seed over existing data, the DB rows kept their old IDs while in-memory arrays held PRNG-generated IDs. The TRUNCATE was positioned after the staff upsert, so no downstream FK references were cleared before staff IDs diverged.

Test plan

  • Seed runs successfully on a database with existing seed data (idempotent re-run)
  • No FK violation errors
  • All 8 staff, 10 services, ~2500 appointments created
  • pnpm test passes

🤖 Generated with Claude Code

## Summary - Move TRUNCATE statement before the staff upsert block so downstream FK references (appointments, invoices, etc.) are cleared before staff IDs are re-upserted - Add `id: s.id` to the staff upsert `onConflictDoUpdate` set clause so re-seeded rows get their IDs overwritten to match the deterministic PRNG values - Prevents appointments insert from referencing staff IDs that don't exist in the DB after a re-seed ## Root Cause On re-seed over existing data, the DB rows kept their **old** IDs while in-memory arrays held PRNG-generated IDs. The TRUNCATE was positioned *after* the staff upsert, so no downstream FK references were cleared before staff IDs diverged. ## Test plan - [ ] Seed runs successfully on a database with existing seed data (idempotent re-run) - [ ] No FK violation errors - [ ] All 8 staff, 10 services, ~2500 appointments created - [ ] `pnpm test` passes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
lint-roller-qa[bot] (Migrated from github.com) approved these changes 2026-04-01 13:53:07 +00:00
github-actions[bot] commented 2026-04-01 13:54:50 +00:00 (Migrated from github.com)

Deployed to groombook-dev

Images: pr-199
URL: https://dev.groombook.farh.net

Ready for UAT validation.

## Deployed to groombook-dev **Images:** `pr-199` **URL:** https://dev.groombook.farh.net Ready for UAT validation.
the-dogfather-cto[bot] (Migrated from github.com) approved these changes 2026-04-01 13:55:50 +00:00
the-dogfather-cto[bot] (Migrated from github.com) left a comment

CTO Approved

Reviewed all 4 commits across 6 files. Changes are correct:

  • Migration 0020: safe dedup + UNIQUE(name) constraint on services
  • TRUNCATE repositioned before staff upsert to clear stale FK refs
  • id: s.id added to staff upsert set clause — root cause fix for FK violation
  • All seed paths (main, admin, seedKnownUsers) aligned on ON CONFLICT (name) with consistent b0000001-... deterministic IDs

CI green. Ship it.

**CTO Approved** Reviewed all 4 commits across 6 files. Changes are correct: - Migration 0020: safe dedup + UNIQUE(name) constraint on services - TRUNCATE repositioned before staff upsert to clear stale FK refs - `id: s.id` added to staff upsert set clause — root cause fix for FK violation - All seed paths (main, admin, seedKnownUsers) aligned on ON CONFLICT (name) with consistent `b0000001-...` deterministic IDs CI green. Ship it.
github-actions[bot] commented 2026-04-01 14:15:59 +00:00 (Migrated from github.com)

Deployed to groombook-dev

Images: pr-199
URL: https://dev.groombook.farh.net

Ready for UAT validation.

## Deployed to groombook-dev **Images:** `pr-199` **URL:** https://dev.groombook.farh.net Ready for UAT validation.
This repo is archived. You cannot comment on pull requests.