From 3975240a48577d1d935fa9102140153ddf2025e9 Mon Sep 17 00:00:00 2001 From: Barkley Trimsworth Date: Mon, 30 Mar 2026 14:29:59 +0000 Subject: [PATCH] fix(db): seed ON CONFLICT target uses clients.id instead of non-unique clients.email GRO-298: Batch client insert and UAT test client insert both used schema.clients.email as the ON CONFLICT target, but clients.email has no unique constraint in the schema, causing the seed to crash with: PostgresError: there is no unique or exclusion constraint matching the ON CONFLICT specification Both calls now use schema.clients.id (the primary key) as the target, and include email in the set clause since we're no longer updating on email match. Co-Authored-By: Paperclip --- packages/db/src/seed.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/db/src/seed.ts b/packages/db/src/seed.ts index 645ff18..9000d99 100644 --- a/packages/db/src/seed.ts +++ b/packages/db/src/seed.ts @@ -516,8 +516,8 @@ async function seed() { await db.insert(schema.clients) .values(client) .onConflictDoUpdate({ - target: schema.clients.email, - set: { name: client.name, phone: client.phone, address: client.address, notes: client.notes, emailOptOut: client.emailOptOut }, + target: schema.clients.id, + set: { name: client.name, email: client.email, phone: client.phone, address: client.address, notes: client.notes, emailOptOut: client.emailOptOut }, }); } @@ -570,7 +570,7 @@ async function seed() { for (const uc of uatClients) { await db.insert(schema.clients) .values({ id: uc.id, name: uc.name, email: uc.email, phone: uc.phone, address: uc.address }) - .onConflictDoUpdate({ target: schema.clients.email, set: { name: uc.name, phone: uc.phone, address: uc.address } }); + .onConflictDoUpdate({ target: schema.clients.id, set: { name: uc.name, email: uc.email, phone: uc.phone, address: uc.address } }); await db.insert(schema.pets) .values({ id: uc.petId, clientId: uc.id, name: uc.petName, species: "Dog", breed: uc.petBreed, weightKg: "25.00", dateOfBirth: new Date("2021-03-15T00:00:00Z") }) .onConflictDoUpdate({ target: schema.pets.id, set: { clientId: uc.id, name: uc.petName, species: "Dog", breed: uc.petBreed, weightKg: "25.00", dateOfBirth: new Date("2021-03-15T00:00:00Z") } }); -- 2.52.0