rallly/packages/database/prisma/schema.prisma
Luke Vella 7fc08c6736 ✏️ Fix typo
2023-03-31 19:16:58 +01:00

132 lines
4 KiB
Text

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
relationMode = "prisma"
}
generator client {
provider = "prisma-client-js"
binaryTargets = ["native"]
}
model User {
id String @id @default(cuid())
name String
email String @unique() @db.Citext
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")
comments Comment[]
polls Poll[]
watcher Watcher[]
@@map("users")
}
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?
user User? @relation(fields: [userId], references: [id])
userId String @map("user_id")
votes Vote[]
timeZone String? @map("time_zone")
options Option[]
participants Participant[]
watchers Watcher[]
demo Boolean @default(false)
comments Comment[]
legacy Boolean @default(false)
closed Boolean @default(false)
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")
@@index([userId], type: Hash)
@@map("polls")
}
model Watcher {
id Int @id @default(autoincrement())
userId String @map("user_id")
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])
@@index([userId], type: Hash)
@@index([pollId], type: Hash)
@@map("watchers")
}
model Participant {
id String @id @default(cuid())
name String
email String?
userId String? @map("user_id")
poll Poll @relation(fields: [pollId], references: [id])
pollId String @map("poll_id")
votes Vote[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")
@@index([pollId], type: Hash)
@@map("participants")
}
model Option {
id String @id @default(cuid())
start DateTime @db.Timestamp(0)
duration Int @default(0) @map("duration_minutes")
pollId String @map("poll_id")
poll Poll @relation(fields: [pollId], references: [id])
createdAt DateTime @default(now()) @map("created_at")
@@index([pollId], type: Hash)
@@map("options")
}
enum VoteType {
yes
no
ifNeedBe
@@map("vote_type")
}
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")
poll Poll @relation(fields: [pollId], references: [id])
pollId String @map("poll_id")
type VoteType @default(yes)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")
@@index([participantId], type: Hash)
@@index([pollId], type: Hash)
@@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])
userId String? @map("user_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")
@@index([userId], type: Hash)
@@index([pollId], type: Hash)
@@map("comments")
}