fix(db): add migration 0020 UNIQUE(name) + align admin seed ON CONFLICT #198

Merged
groombook-engineer[bot] merged 4 commits from fix/gro-360-yq-compound-assignment into main 2026-04-01 20:06:01 +00:00

4 Commits

Author SHA1 Message Date
groombook-ceo[bot] 361567dc3b Merge branch 'main' into fix/gro-360-yq-compound-assignment 2026-04-01 19:56:01 +00:00
groombook-engineer[bot] 82bf7c6078 fix(ui): replace Super User and Status action buttons with inline toggles
- Super User column now has an inline toggle switch instead of a badge + Grant/Revoke button
- Status column now has an inline toggle switch instead of a badge + Deactivate/Activate button
- Actions column now only has Edit button; Grant SU, Revoke SU, Deactivate, Activate removed
- Both toggles disabled when staff member is the last active super user
- Loading indicator shown while toggling (togglingId === s.id)
- No new dependencies; styled button toggle consistent with existing inline styles

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-01 19:39:21 +00:00
groombook-engineer[bot] cfa28c64b6 fix(db): add migration 0020 for UNIQUE(name) + align admin seed ON CONFLICT
Problem:
- Schema change in eacf8ab added .unique() to services.name
- No migration existed to apply this constraint to the database
- Admin seed and seedKnownUsers still used ON CONFLICT (id) with
  a0000001-... IDs, inconsistent with main seed's b0000001-... IDs
  and ON CONFLICT (name)

Fix:
- Migration 0020: clean up existing duplicate services (keep lowest
  id per name), then add UNIQUE constraint on services.name
- Admin seed (apps/api): switch to ON CONFLICT (name) and b0000001
  IDs to match main seed's servicesDef
- seedKnownUsers (packages/db): same alignment — b0000001 IDs and
  ON CONFLICT (name)

GRO-364: ON CONFLICT (name) eliminates the duplicate-row problem
that the old dedup+ON CONFLICT(id) approach could not solve when
existing rows had non-deterministic IDs.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-01 13:54:54 +00:00
groombook-engineer[bot] 7033cd1d5c fix(db): remove dedup DELETE and use ON CONFLICT (name) for idempotent services seed
The dedup DELETE was causing two problems:
1. FK violation (GRO-365) — deleting services referenced by appointments
2. Duplicate services (GRO-301) — MIN(id) per name could delete the wrong row,
   causing ON CONFLICT (id) to create duplicates on re-run

Fix:
- Remove the dedup DELETE entirely
- Keep TRUNCATE of downstream tables (appointments, invoices, etc.) to clear
  stale data from prior runs
- Change ON CONFLICT target from `id` to `name` with a unique constraint on
  name column — deterministic IDs in servicesDef ensure idempotency

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-01 13:54:54 +00:00