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>
This commit is contained in:
groombook-engineer[bot]
2026-04-01 13:23:11 +00:00
parent 7fb5ddbbd1
commit eacf8abc3b
2 changed files with 8 additions and 11 deletions
+1 -1
View File
@@ -141,7 +141,7 @@ export const pets = pgTable("pets", {
export const services = pgTable("services", {
id: uuid("id").primaryKey().defaultRandom(),
name: text("name").notNull(),
name: text("name").notNull().unique(),
description: text("description"),
basePriceCents: integer("base_price_cents").notNull(),
durationMinutes: integer("duration_minutes").notNull(),