KinglyEndeavors
KinglyEndeavors
PPrisma
Created by KinglyEndeavors on 2/24/2025 in #help-and-questions
CUID Not Auto-Generating
I'm trying to write a seed script to populate my database with mock data, but for whatever reason, I'm getting a null constraint error for the primary key ('_id'), even though my schema is set to autogenerate this. It generates them just fine within my actual app, but it's not for my seed script for whatever reason. Any ideas? (Snippets in thread.)
13 replies
PPrisma
Created by KinglyEndeavors on 7/3/2024 in #help-and-questions
Best Practices for Error Handling When Updating Bridge Table (Composite IDs)
What are the best practices when it comes to going about error handling for a function that is updating a bridge table? Is it necessary to verify to check if the two records that comprises its composite ID (e.g., facilityUuid for the Facility model and workerUuid for the Worker model) before updating it? Or will it check for that on its own as a consequential result? Here's are some snippet examples:
export function updateFacilityWorker(
facilityUuid: FacilityWorker["facilityUuid"],
workerUuid: Worker["uuid"],
data: Omit<Prisma.FacilityWorkerUpdateInput, TimestampFields>
): Promise<UpdatedFacilityWorker> {
return prisma.facilityWorker.update({
select: {
facilityUuid: true,
workerUuid: true,
rating: true,
status: true,
},
where: {
facility_worker_id: { facilityUuid, workerUuid },
},
data,
});
}
export function updateFacilityWorker(
facilityUuid: FacilityWorker["facilityUuid"],
workerUuid: Worker["uuid"],
data: Omit<Prisma.FacilityWorkerUpdateInput, TimestampFields>
): Promise<UpdatedFacilityWorker> {
return prisma.facilityWorker.update({
select: {
facilityUuid: true,
workerUuid: true,
rating: true,
status: true,
},
where: {
facility_worker_id: { facilityUuid, workerUuid },
},
data,
});
}
model FacilityWorker {
facilityUuid String @db.Uuid
facility HealthCareFacility @relation(fields: [facilityUuid], references: [uuid], onDelete: Cascade)

workerUuid String @db.Uuid
worker Worker @relation(fields: [workerUuid], references: [uuid], onDelete: Cascade)

rating Int? @db.SmallInt
status FacilityWorkerStatus @default(Available)

@@id(fields: [facilityUuid, workerUuid], name: "facility_worker_id")
@@index(fields: [facilityUuid, workerUuid, status], name: "worker_status_at_facility")
}
model FacilityWorker {
facilityUuid String @db.Uuid
facility HealthCareFacility @relation(fields: [facilityUuid], references: [uuid], onDelete: Cascade)

workerUuid String @db.Uuid
worker Worker @relation(fields: [workerUuid], references: [uuid], onDelete: Cascade)

rating Int? @db.SmallInt
status FacilityWorkerStatus @default(Available)

@@id(fields: [facilityUuid, workerUuid], name: "facility_worker_id")
@@index(fields: [facilityUuid, workerUuid, status], name: "worker_status_at_facility")
}
16 replies