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
Showing only changes of commit 8928cd8805 - Show all commits
+5 -5
View File
@@ -408,6 +408,10 @@ async function seed() {
{ id: uuid(), name: "Devon Williams", email: "devon@groombook.dev", role: "groomer" as const, isSuperUser: false },
];
// Truncate downstream tables before staff upsert — clears stale appointments
// and other FK references to old staff IDs so the id column can safely be updated
await db.execute(sql`TRUNCATE appointments, invoices, invoice_line_items, invoice_tip_splits, grooming_visit_logs CASCADE`);
const allStaff = [...managerStaff, ...receptionistStaff, ...groomers, ...bathers];
for (const s of allStaff) {
await db.insert(schema.staff)
@@ -421,15 +425,11 @@ async function seed() {
})
.onConflictDoUpdate({
target: schema.staff.email,
set: { name: s.name, role: s.role, isSuperUser: s.isSuperUser, active: true },
set: { id: s.id, name: s.name, role: s.role, isSuperUser: s.isSuperUser, active: true },
});
}
console.log(`✓ Created ${allStaff.length} staff (1 manager, 1 receptionist, 3 groomers, 3 bathers)`);
// Truncate downstream tables before services upsert — clears stale appointments
// from prior seed runs so the FK constraint on service_id is never violated
await db.execute(sql`TRUNCATE appointments, invoices, invoice_line_items, invoice_tip_splits, grooming_visit_logs CASCADE`);
// ── Services ──
// Upsert services using name as unique key. With deterministic IDs in
// servicesDef and TRUNCATE clearing downstream tables first, this is