nenadv
06/09/2021, 3:39 PMif (!userId) {
return;
}
let newUser;
const checkIfNewUserMigration = await prismaClient.user.findFirst({
where: {
systemId: userId,
},
select: {
systemId: true,
id: true,
},
});
if (!checkIfNewUserMigration) {
newUser = await prismaClient.user.create({
data: {
systemId: userId,
firstName: firstName,
lastName: lastName,
avatar: avatar,
conversationMemberships: {
create: {
conversation: { connect: { id: conversation.id } },
},
},
},
select: {
id: true,
systemId: true,
},
});
} else {
newUser = checkIfNewUserMigration;
}
produce this error
throw new import_engine_core.PrismaClientKnownRequestError(message, e.code, this.prisma._clientVersion, e.meta);
^
Error:
Invalid `prisma.user.create()` invocation:
Unique constraint failed on the constraint: `systemId_unique`
?
There are explicit checks in the code to avoid this as you can see. Can also provide schema etc. if needed?
Also do add, on the sample batch data I'm testing this it randomly breaks, so it isn't specific data which causes the issues, sometimes it is the 100. entry, sometimes 130.Samrith Shankar
06/09/2021, 3:46 PMSamrith Shankar
06/09/2021, 3:48 PMfindUniquenenadv
06/09/2021, 3:49 PM2.21.2
i will try it with findUniquenenadv
06/09/2021, 3:57 PMfindFirst , it doesnt make senseSamrith Shankar
06/09/2021, 3:58 PMif (!userId) {
return;
}
let newUser;
const checkIfNewUserMigration = await prismaClient.user.findFirst({
where: {
systemId: userId,
},
select: {
systemId: true,
id: true,
},
});
if (!checkIfNewUserMigration) {
console.log("No checkIfNewUserMigration", checkIfNewUserMigration);
newUser = await prismaClient.user.create({
data: {
systemId: userId,
firstName: firstName,
lastName: lastName,
avatar: avatar,
conversationMemberships: {
create: {
conversation: { connect: { id: conversation.id } },
},
},
},
select: {
id: true,
systemId: true,
},
});
} else {
newUser = checkIfNewUserMigration;
}Samrith Shankar
06/09/2021, 3:58 PMnenadv
06/09/2021, 4:06 PMSamrith Shankar
06/09/2021, 4:08 PMnenadv
06/10/2021, 3:41 PMSamrith Shankar
06/10/2021, 3:43 PM