diff --git a/prisma/migrations/20230717010129_cascade_survey_fks/migration.sql b/prisma/migrations/20230717010129_cascade_survey_fks/migration.sql new file mode 100644 index 0000000..edf0e16 --- /dev/null +++ b/prisma/migrations/20230717010129_cascade_survey_fks/migration.sql @@ -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; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 8949ae9..89bfea9 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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])