rallly/packages/database/prisma/models/poll.prisma
2025-05-22 10:45:34 +01:00

166 lines
5.4 KiB
Text

enum ParticipantVisibility {
full
scoresOnly
limited
@@map("participant_visibility")
}
enum PollStatus {
live
paused
finalized
@@map("poll_status")
}
model Poll {
id String @id @unique @map("id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deadline DateTime?
title String
description String?
location String?
userId String? @map("user_id")
guestId String? @map("guest_id")
timeZone String? @map("time_zone")
status PollStatus @default(live)
deleted Boolean @default(false)
deletedAt DateTime? @map("deleted_at")
touchedAt DateTime @default(now()) @map("touched_at") // @deprecated
participantUrlId String @unique @map("participant_url_id")
adminUrlId String @unique @map("admin_url_id")
eventId String? @unique @map("event_id")
scheduledEventId String? @map("scheduled_event_id")
hideParticipants Boolean @default(false) @map("hide_participants")
hideScores Boolean @default(false) @map("hide_scores")
disableComments Boolean @default(false) @map("disable_comments")
requireParticipantEmail Boolean @default(false) @map("require_participant_email")
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
event Event? @relation(fields: [eventId], references: [id], onDelete: SetNull)
scheduledEvent ScheduledEvent? @relation(fields: [scheduledEventId], references: [id], onDelete: SetNull)
options Option[]
participants Participant[]
watchers Watcher[]
comments Comment[]
votes Vote[]
views PollView[]
@@index([guestId])
@@map("polls")
}
model Watcher {
id Int @id @default(autoincrement())
userId String @map("user_id")
pollId String @map("poll_id")
createdAt DateTime @default(now()) @map("created_at")
poll Poll @relation(fields: [pollId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([pollId], type: Hash)
@@map("watchers")
}
model Participant {
id String @id @default(cuid())
name String
email String?
userId String? @map("user_id")
guestId String? @map("guest_id")
pollId String @map("poll_id")
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[]
poll Poll @relation(fields: [pollId], references: [id], onDelete: Cascade)
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
@@index([guestId], type: Hash)
@@index([pollId], type: Hash)
@@map("participants")
}
model Option {
id String @id @default(cuid())
startTime DateTime @map("start_time") @db.Timestamp(0)
duration Int @default(0) @map("duration_minutes")
pollId String @map("poll_id")
createdAt DateTime @default(now()) @map("created_at")
votes Vote[]
poll Poll @relation(fields: [pollId], references: [id], onDelete: Cascade)
@@index([pollId], type: Hash)
@@map("options")
}
enum VoteType {
yes
no
ifNeedBe
@@map("vote_type")
}
model Vote {
id String @id @default(cuid())
participantId String @map("participant_id")
optionId String @map("option_id")
pollId String @map("poll_id")
type VoteType @default(yes)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")
participant Participant @relation(fields: [participantId], references: [id], onDelete: Cascade)
option Option @relation(fields: [optionId], references: [id], onDelete: Cascade)
poll Poll @relation(fields: [pollId], references: [id], onDelete: Cascade)
@@index([pollId], type: Hash)
@@index([participantId], type: Hash)
@@index([optionId], type: Hash)
@@map("votes")
}
model Comment {
id String @id @default(cuid())
content String
pollId String @map("poll_id")
authorName String @map("author_name")
userId String? @map("user_id")
guestId String? @map("guest_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")
poll Poll @relation(fields: [pollId], references: [id], onDelete: Cascade)
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([guestId], type: Hash)
@@index([pollId], type: Hash)
@@map("comments")
}
model PollView {
id String @id @default(cuid())
pollId String @map("poll_id")
ipAddress String? @map("ip_address")
userId String? @map("user_id")
userAgent String? @map("user_agent")
viewedAt DateTime @default(now()) @map("viewed_at")
poll Poll @relation(fields: [pollId], references: [id], onDelete: Cascade)
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
@@index([pollId], type: Hash)
@@index([userId], type: Hash)
@@index([viewedAt])
@@map("poll_views")
}