rallly/packages/database/prisma/schema.prisma
2025-02-27 15:23:01 +00:00

290 lines
8.3 KiB
Text

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
binaryTargets = ["native"]
}
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")
comments Comment[]
polls Poll[]
watcher Watcher[]
events Event[]
accounts Account[]
participants Participant[]
paymentMethods PaymentMethod[]
subscription Subscription? @relation("UserToSubscription")
@@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")
closed Boolean @default(false) // @deprecated
status PollStatus @default(live)
deleted Boolean @default(false)
deletedAt DateTime? @map("deleted_at")
touchedAt DateTime @default(now()) @map("touched_at")
participantUrlId String @unique @map("participant_url_id")
adminUrlId String @unique @map("admin_url_id")
eventId String? @unique @map("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)
options Option[]
participants Participant[]
watchers Watcher[]
comments Comment[]
votes Vote[]
@@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 VerificationToken {
identifier String @db.Citext
token String @unique
expires DateTime
@@unique([identifier, token])
@@map("verification_tokens")
}