Jaye
10/26/2021, 6:17 PMresponses.map(r => {
if (emailSchema.isValidSync(creatorEmail))
await db.user.upsert({
where: {
email: r.creatorEmail,
},
update: {},
create: {
email: r.creatorEmail,
},
})
if (emailSchema.isValidSync(approverEmail))
await db.user.upsert({
where: {
email: r.approverEmail,
},
update: {},
create: {
email: r.approverEmail,
},
})
})
the user model has a unique constraint on the email column:
model User {
id String @id @default(cuid())
email String? @unique
// etc...
}
i intermittently get `Unique constraint failed on the fields: (email
)` errors 😞
is this a race condition? if so, how can i fix it?Ryan
10/27/2021, 12:08 PMmap
running everything asynchronously and you have a condition with upsert
I would suggest using interactive transactions in this case so that there are no conflicts.Jaye
10/27/2021, 1:04 PMJaye
10/27/2021, 1:04 PMJaye
10/27/2021, 1:04 PM