Skip to content

Commit

Permalink
fix: cascade deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
qin-guan committed Jul 17, 2023
1 parent 633dbbb commit eec6bcf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions prisma/migrations/20230717010129_cascade_survey_fks/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- DropForeignKey
ALTER TABLE "Response" DROP CONSTRAINT "Response_respondentId_fkey";

-- DropForeignKey
ALTER TABLE "Response" DROP CONSTRAINT "Response_surveyId_fkey";

-- AddForeignKey
ALTER TABLE "Response" ADD CONSTRAINT "Response_surveyId_fkey" FOREIGN KEY ("surveyId") REFERENCES "Survey"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Response" ADD CONSTRAINT "Response_respondentId_fkey" FOREIGN KEY ("respondentId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
4 changes: 2 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ model Response {
timestamp DateTime @default(now())
data Json
survey Survey @relation(fields: [surveyId], references: [id])
survey Survey @relation(fields: [surveyId], references: [id], onDelete: Cascade)
surveyId String
respondent User @relation(fields: [respondentId], references: [id])
respondent User @relation(fields: [respondentId], references: [id], onDelete: Cascade)
respondentId String
@@unique([surveyId, respondentId])
Expand Down

0 comments on commit eec6bcf

Please sign in to comment.