rallly/packages/database/prisma/schema.prisma
2025-04-22 14:28:15 +01:00

392 lines
12 KiB
Text

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
binaryTargets = ["native"]
previewFeatures = ["relationJoins"]
}
enum TimeFormat {
hours12
hours24
@@map("time_format")
}
model Account {
id String @id @default(cuid())
userId String @map("user_id")
type String
provider String
providerAccountId String @map("provider_account_id")
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
@@map("accounts")
}
model User {
id String @id @default(cuid())
name String
email String @unique() @db.Citext
emailVerified DateTime? @map("email_verified")
image String?
timeZone String? @map("time_zone")
weekStart Int? @map("week_start")
timeFormat TimeFormat? @map("time_format")
locale String?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")
customerId String? @map("customer_id")
banned Boolean @default(false)
bannedAt DateTime? @map("banned_at")
banReason String? @map("ban_reason")
comments Comment[]
polls Poll[]
watcher Watcher[]
events Event[]
accounts Account[]
participants Participant[]
paymentMethods PaymentMethod[]
subscription Subscription? @relation("UserToSubscription")
pollViews PollView[]
scheduledEvents ScheduledEvent[]
scheduledEventInvites ScheduledEventInvite[]
@@map("users")
}
enum SubscriptionStatus {
incomplete
incomplete_expired
active
paused
trialing
past_due
canceled
unpaid
@@map("subscription_status")
}
enum SubscriptionInterval {
day
week
month
year
@@map("subscription_interval")
}
model PaymentMethod {
id String @id
userId String @map("user_id")
type String
data Json
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("payment_methods")
}
model Subscription {
id String @id
priceId String @map("price_id")
amount Int
status SubscriptionStatus
active Boolean
currency String
interval SubscriptionInterval
createdAt DateTime @default(now()) @map("created_at")
periodStart DateTime @map("period_start")
periodEnd DateTime @map("period_end")
cancelAtPeriodEnd Boolean @default(false) @map("cancel_at_period_end")
userId String @unique @map("user_id")
user User @relation("UserToSubscription", fields: [userId], references: [id], onDelete: Cascade)
@@map("subscriptions")
}
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 Event {
id String @id @default(cuid())
userId String @map("user_id")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
optionId String @map("option_id")
title String
start DateTime @db.Timestamp(0)
duration Int @default(0) @map("duration_minutes")
createdAt DateTime @default(now()) @map("created_at")
poll Poll?
@@index([userId], type: Hash)
@@map("events")
}
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")
}
model VerificationToken {
identifier String @db.Citext
token String @unique
expires DateTime
@@unique([identifier, token])
@@map("verification_tokens")
}
enum ScheduledEventStatus {
confirmed
canceled
unconfirmed
@@map("scheduled_event_status")
}
enum ScheduledEventInviteStatus {
pending
accepted
declined
tentative
@@map("scheduled_event_invite_status")
}
model ScheduledEvent {
id String @id @default(cuid())
userId String @map("user_id")
title String
description String?
location String?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
status ScheduledEventStatus @default(confirmed)
timeZone String? @map("time_zone")
start DateTime
end DateTime
allDay Boolean @default(false) @map("all_day")
deletedAt DateTime? @map("deleted_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
rescheduledDates RescheduledEventDate[]
invites ScheduledEventInvite[]
polls Poll[]
@@map("scheduled_events")
}
model RescheduledEventDate {
id String @id @default(cuid())
scheduledEventId String @map("scheduled_event_id")
start DateTime @map("start")
end DateTime @map("end")
allDay Boolean @default(false) @map("all_day")
createdAt DateTime @default(now()) @map("created_at")
scheduledEvent ScheduledEvent @relation(fields: [scheduledEventId], references: [id], onDelete: Cascade)
@@index([scheduledEventId])
@@map("rescheduled_event_dates")
}
model ScheduledEventInvite {
id String @id @default(cuid())
scheduledEventId String @map("scheduled_event_id")
inviteeName String @map("invitee_name")
inviteeEmail String @map("invitee_email")
inviteeId String? @map("invitee_id")
inviteeTimeZone String? @map("invitee_time_zone")
status ScheduledEventInviteStatus @default(pending)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
scheduledEvent ScheduledEvent @relation(fields: [scheduledEventId], references: [id], onDelete: Cascade)
user User? @relation(fields: [inviteeId], references: [id], onDelete: SetNull) // Optional relation to User model
@@unique([scheduledEventId, inviteeEmail])
@@unique([scheduledEventId, inviteeId])
@@index([scheduledEventId])
@@index([inviteeId])
@@index([inviteeEmail])
@@map("scheduled_event_invites")
}