mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-28 13:47:43 +02:00
Cascade delete
This commit is contained in:
parent
40861f67fc
commit
225d1e6b6a
2 changed files with 50 additions and 11 deletions
|
@ -0,0 +1,32 @@
|
|||
-- DropForeignKey
|
||||
ALTER TABLE "comments" DROP CONSTRAINT "comments_poll_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "options" DROP CONSTRAINT "options_poll_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "participants" DROP CONSTRAINT "participants_poll_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "polls" DROP CONSTRAINT "polls_user_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "watchers" DROP CONSTRAINT "watchers_poll_id_fkey";
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "polls" ADD CONSTRAINT "polls_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "watchers" ADD CONSTRAINT "watchers_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "participants" ADD CONSTRAINT "participants_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "options" ADD CONSTRAINT "options_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "votes" ADD CONSTRAINT "votes_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "comments" ADD CONSTRAINT "comments_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -138,12 +138,13 @@ model Poll {
|
|||
disableComments Boolean @default(false) @map("disable_comments")
|
||||
requireParticipantEmail Boolean @default(false) @map("require_participant_email")
|
||||
|
||||
user User? @relation(fields: [userId], references: [id])
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
event Event? @relation(fields: [eventId], references: [id])
|
||||
options Option[]
|
||||
participants Participant[]
|
||||
watchers Watcher[]
|
||||
comments Comment[]
|
||||
options Option[] @relation("PollToOptions")
|
||||
participants Participant[] @relation("PollToParticipants")
|
||||
watchers Watcher[] @relation("PollToWatchers")
|
||||
comments Comment[] @relation("PollToComments")
|
||||
votes Vote[] @relation("PollToVotes")
|
||||
|
||||
@@map("polls")
|
||||
}
|
||||
|
@ -169,7 +170,8 @@ model Watcher {
|
|||
user User @relation(fields: [userId], references: [id])
|
||||
pollId String @map("poll_id")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
poll Poll @relation(fields: [pollId], references: [id])
|
||||
|
||||
poll Poll @relation("PollToWatchers", fields: [pollId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@map("watchers")
|
||||
}
|
||||
|
@ -179,15 +181,16 @@ model Participant {
|
|||
name String
|
||||
email String?
|
||||
userId String? @map("user_id")
|
||||
poll Poll @relation(fields: [pollId], references: [id])
|
||||
poll Poll @relation("PollToParticipants", fields: [pollId], references: [id], onDelete: Cascade)
|
||||
pollId String @map("poll_id")
|
||||
votes Vote[]
|
||||
locale String?
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime? @updatedAt @map("updated_at")
|
||||
deleted Boolean @default(false)
|
||||
deletedAt DateTime? @map("deleted_at")
|
||||
|
||||
votes Vote[] @relation("ParticipantToVotes")
|
||||
|
||||
@@map("participants")
|
||||
}
|
||||
|
||||
|
@ -196,7 +199,7 @@ model Option {
|
|||
startTime DateTime @map("start_time") @db.Timestamp(0)
|
||||
duration Int @default(0) @map("duration_minutes")
|
||||
pollId String @map("poll_id")
|
||||
poll Poll @relation(fields: [pollId], references: [id])
|
||||
poll Poll @relation("PollToOptions", fields: [pollId], references: [id], onDelete: Cascade)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
@@map("options")
|
||||
|
@ -212,7 +215,6 @@ enum VoteType {
|
|||
|
||||
model Vote {
|
||||
id String @id @default(cuid())
|
||||
participant Participant @relation(fields: [participantId], references: [id], onDelete: Cascade)
|
||||
participantId String @map("participant_id")
|
||||
optionId String @map("option_id")
|
||||
pollId String @map("poll_id")
|
||||
|
@ -220,13 +222,15 @@ model Vote {
|
|||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime? @updatedAt @map("updated_at")
|
||||
|
||||
|
||||
participant Participant @relation("ParticipantToVotes", fields: [participantId], references: [id], onDelete: Cascade)
|
||||
poll Poll @relation("PollToVotes", fields: [pollId], references: [id], onDelete: Cascade)
|
||||
@@map("votes")
|
||||
}
|
||||
|
||||
model Comment {
|
||||
id String @id @default(cuid())
|
||||
content String
|
||||
poll Poll @relation(fields: [pollId], references: [id])
|
||||
pollId String @map("poll_id")
|
||||
authorName String @map("author_name")
|
||||
user User? @relation(fields: [userId], references: [id])
|
||||
|
@ -234,6 +238,9 @@ model Comment {
|
|||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime? @updatedAt @map("updated_at")
|
||||
|
||||
|
||||
poll Poll @relation("PollToComments", fields: [pollId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@map("comments")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue