twitch-clone/backend/prisma/schema.prisma
2025-07-21 06:47:16 +03:00

172 lines
6.2 KiB
Plaintext

generator client {
provider = "prisma-client-js"
output = "./generated"
}
datasource db {
provider = "postgresql"
url = env("POSTGRES_URI")
}
model Stream {
id String @id @default(uuid())
title String
thumbnailUrl String? @map("thumbnail_url")
ingressId String? @unique @map("ingress_id")
serverUrl String? @map("server_url")
key String? @map("key")
isLive Boolean @default(false) @map("is_live")
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String? @unique @map("user_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
category Category? @relation(fields: [categoryId], references: [id], onDelete: Cascade)
categoryId String? @map("category_id")
chatMessages ChatMessage[]
isChatEnable Boolean @default(true) @map("is_chat_enable")
isChatFollowersOnly Boolean @default(false) @map("is_chat_followers_onlys")
isChatPremiumFollowersOnly Boolean @default(false) @map("is_chat_premium_followers_onlys")
@@map("stream")
}
model ChatMessage {
id String @id @default(uuid())
text String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String @map("user_id")
stream Stream @relation(fields: [streamId], references: [id], onDelete: Cascade)
streamId String @map("stream_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("chat_messages")
}
model Follow {
id String @id @default(uuid())
follower User @relation(name: "followers", fields: [followerId], references: [id], onDelete: Cascade)
followerId String @map("follower_id")
following User @relation(name: "followings", fields: [followingId], references: [id], onDelete: Cascade)
followingId String @map("following_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@unique([followingId, followerId])
@@index([followerId])
@@index([followingId])
@@map("follows")
}
model SocialLink {
id String @id @default(uuid())
title String
url String
position Int
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String? @map("user_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("social_links")
}
model User {
id String @id @default(uuid())
email String @unique
password String
name String @unique
displayName String @map("display_name")
avatar String?
bio String?
token Token[]
isVerified Boolean @default(false) @map("is_verified")
isEmailVerified Boolean @default(false) @map("is_email_verified")
isTotpEnabled Boolean @default(false) @map("is_totp_enabled")
isDeactivated Boolean @default(false) @map("is_deactivated")
deactivatedAt DateTime? @map("deactivated_at")
socialLink SocialLink[]
totpSecret String? @map("totp_secret")
stream Stream?
chatMessages ChatMessage[]
followers Follow[] @relation(name: "followers")
followings Follow[] @relation(name: "followings")
notifications Notification[]
notificationSettings NotificationSettings?
telegramId String? @unique @map("telegram_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("users")
}
model Category {
id String @id @default(uuid())
title String
slug String @unique
description String?
thumbnailUrl String @map("thumbnail_url")
streams Stream[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("categories")
}
model Token {
id String @id @default(uuid())
token String @unique
type TokenType
expiresIn DateTime @map("expires_in")
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String? @map("user_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("tokens")
}
model Notification {
id String @id @default(uuid())
text String
type NotificationType
isRead Boolean @default(false) @map("is_read")
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String? @map("user_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("notifications")
}
model NotificationSettings {
id String @id @default(uuid())
siteNotifications Boolean @default(true) @map("site_notifications")
telegramNotifications Boolean @default(true) @map("telegram_notifications")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String @unique @map("user_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("notification_settings")
}
enum NotificationType {
STREAM_START
NEW_FOLLOWER
NEW_SPONSORSHIP
ENABLE_TWO_FACTOR
VERIFIED_CHANNEL
@@map("notification_types")
}
enum TokenType {
EMAIL_VERIFY
PASSWORD_RESET
DEACTIVATE_ACCOUNT
TELEGRAM_AUTH
@@map("token_types")
}