From f1a690dcf5edbcb5377a04b4ef5b65035ae7eb7d Mon Sep 17 00:00:00 2001 From: Roland Schlaefli Date: Tue, 11 Oct 2022 21:12:16 +0200 Subject: [PATCH] enhance(prisma): make user proposal many-to-many explicit --- prisma/schema.prisma | 50 +++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index f2dff5c..9a44350 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -61,14 +61,12 @@ model User { accounts Account[] - assignedProposal Proposal? @relation("proposalAssignment") - assignedProposalId String? - - supervises Proposal[] @relation("proposalSupervision") - appliedFor Proposal[] @relation("proposalApplication") - createdAt DateTime @default(now()) updatedAt DateTime @default(now()) @updatedAt + + assignedProposals UserProposalAssignment[] + supervisedProposals UserProposalSupervision[] + appliedFor UserProposalApplication[] } model VerificationToken { @@ -93,12 +91,40 @@ model Proposal { type ProposalType status ProposalStatus @default(OPEN) - assignedTo User? @relation("proposalAssignment", fields: [assignedToStudentId], references: [id]) - assignedToStudentId String? @unique - - supervisedBy User[] @relation("proposalSupervision") - applicants User[] @relation("proposalApplication") - createdAt DateTime @default(now()) updatedAt DateTime @default(now()) @updatedAt + + assignedTo UserProposalAssignment[] + supervisedBy UserProposalSupervision[] + applications UserProposalApplication[] +} + +model UserProposalAssignment { + proposal Proposal @relation(fields: [proposalId], references: [id]) + proposalId String + + user User @relation(fields: [userId], references: [id]) + userId String + + @@unique([proposalId, userId]) +} + +model UserProposalSupervision { + proposal Proposal @relation(fields: [proposalId], references: [id]) + proposalId String + + user User @relation(fields: [userId], references: [id]) + userId String + + @@unique([proposalId, userId]) +} + +model UserProposalApplication { + proposal Proposal @relation(fields: [proposalId], references: [id]) + proposalId String + + user User @relation(fields: [userId], references: [id]) + userId String + + @@unique([proposalId, userId]) }