PanMan
05/10/2022, 7:54 AMUnique constraint failed on the constraint: `stats_company_id_day_stat_type_context_key`
Isn’t the idea of the upsert it doesn’t fail but does the update, then?? I’m doing:
prisma.stats.upsert({
create: stat,
update: stat,
where: {
company_id_day_stat_type_context: {
company_id: companyId,
day: stat.day,
context: stat.context || "",
stat_type: stat.stat_type,
},
},
});Nurul
05/10/2022, 10:19 AMPanMan
05/10/2022, 12:47 PMPanMan
05/10/2022, 12:48 PMNurul
05/10/2022, 12:53 PMPanMan
05/10/2022, 12:55 PMPanMan
05/10/2022, 12:56 PMNurul
05/11/2022, 8:31 AMPanMan
05/11/2022, 9:34 AMPanMan
05/11/2022, 9:34 AMconst toUpsert = stats.map((stat) => {
return prisma.stats.upsert({
create: stat,
// update: stat,
update: {},
where: {
company_id_day_stat_type_context: {
company_id: stat.company_id,
day: stat.day,
context: stat.context || "",
stat_type: stat.stat_type,
},
},
});
});
await Promise.all(toUpsert);PanMan
05/11/2022, 9:34 AMPanMan
05/11/2022, 9:35 AMPanMan
05/11/2022, 9:35 AMPanMan
05/11/2022, 9:35 AMPanMan
05/11/2022, 9:35 AMmodel stats {
id String @id @default(uuid()) @db.Char(36)
company_id String @db.Char(36)
day DateTime @db.Date
stat_type StatType
stat_value Int
context String? //Map or location or not, when full company
created DateTime @default(now())
updated_at DateTime @updatedAt
company company @relation(fields: [company_id], references: [id])
/// Only one unique stat per day per context per company
@@unique([company_id, day, stat_type, context])
@@index([day, company_id])
@@index([context])
}