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 <noreply@paperclip.ing>
This commit is contained in:
Barkley Trimsworth
2026-03-30 14:29:59 +00:00
parent b385b32120
commit 3975240a48
+3 -3
View File
@@ -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") } });