156 lines
3.9 KiB
Text
156 lines
3.9 KiB
Text
// This is your Prisma schema file,
|
||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||
|
||
generator client {
|
||
provider = "prisma-client-js"
|
||
}
|
||
|
||
datasource db {
|
||
provider = "postgresql"
|
||
}
|
||
|
||
model User {
|
||
id String @id @default(uuid())
|
||
email String? @unique
|
||
name String?
|
||
password String? // For optional email/password admin auth
|
||
role UserRole @default(USER)
|
||
telegramId String? @unique
|
||
createdAt DateTime @default(now())
|
||
|
||
// Связи
|
||
hostedRooms Room[] @relation("HostedRooms")
|
||
participants Participant[]
|
||
questionPacks QuestionPack[]
|
||
|
||
// Статистика
|
||
gamesPlayed Int @default(0)
|
||
gamesWon Int @default(0)
|
||
totalPoints Int @default(0)
|
||
}
|
||
|
||
model Room {
|
||
id String @id @default(uuid())
|
||
code String @unique // 6-символьный код
|
||
status RoomStatus @default(WAITING)
|
||
hostId String
|
||
createdAt DateTime @default(now())
|
||
expiresAt DateTime
|
||
|
||
// Настройки
|
||
maxPlayers Int @default(10)
|
||
allowSpectators Boolean @default(true)
|
||
timerEnabled Boolean @default(false)
|
||
timerDuration Int @default(30)
|
||
questionPackId String?
|
||
autoAdvance Boolean @default(false)
|
||
voiceMode Boolean @default(false) // Голосовой режим
|
||
|
||
// Состояние игры
|
||
currentQuestionIndex Int @default(0)
|
||
revealedAnswers Json @default("{}")
|
||
currentPlayerId String?
|
||
isGameOver Boolean @default(false)
|
||
|
||
// Метрики
|
||
totalQuestions Int @default(0)
|
||
answeredQuestions Int @default(0)
|
||
startedAt DateTime?
|
||
finishedAt DateTime?
|
||
|
||
// Временный пак для комнаты (если хост редактирует вопросы)
|
||
customQuestions Json? // Кастомные вопросы для этой комнаты
|
||
|
||
// Связи
|
||
host User @relation("HostedRooms", fields: [hostId], references: [id])
|
||
participants Participant[]
|
||
questionPack QuestionPack? @relation(fields: [questionPackId], references: [id])
|
||
gameHistory GameHistory?
|
||
}
|
||
|
||
enum RoomStatus {
|
||
WAITING
|
||
PLAYING
|
||
FINISHED
|
||
}
|
||
|
||
model Participant {
|
||
id String @id @default(uuid())
|
||
userId String
|
||
roomId String
|
||
name String
|
||
role ParticipantRole
|
||
score Int @default(0)
|
||
joinedAt DateTime @default(now())
|
||
isActive Boolean @default(true)
|
||
|
||
user User @relation(fields: [userId], references: [id])
|
||
room Room @relation(fields: [roomId], references: [id], onDelete: Cascade)
|
||
|
||
@@unique([userId, roomId])
|
||
}
|
||
|
||
enum ParticipantRole {
|
||
HOST
|
||
PLAYER
|
||
SPECTATOR
|
||
}
|
||
|
||
enum UserRole {
|
||
USER
|
||
ADMIN
|
||
}
|
||
|
||
model QuestionPack {
|
||
id String @id @default(uuid())
|
||
name String
|
||
description String
|
||
category String
|
||
isPublic Boolean @default(false)
|
||
createdBy String
|
||
createdAt DateTime @default(now())
|
||
updatedAt DateTime @updatedAt
|
||
|
||
questions Json // Массив вопросов с ответами
|
||
questionCount Int @default(0)
|
||
timesUsed Int @default(0)
|
||
rating Float @default(0)
|
||
|
||
creator User @relation(fields: [createdBy], references: [id])
|
||
rooms Room[]
|
||
}
|
||
|
||
model GameHistory {
|
||
id String @id @default(uuid())
|
||
roomId String @unique
|
||
roomCode String
|
||
questionPackId String
|
||
startedAt DateTime
|
||
finishedAt DateTime
|
||
|
||
players Json // { userId: { name, score, rank } }
|
||
statistics Json // Детальная статистика игры
|
||
timeline Json // История событий игры
|
||
|
||
room Room @relation(fields: [roomId], references: [id], onDelete: Cascade)
|
||
}
|
||
|
||
model AdminAuthCode {
|
||
id String @id @default(uuid())
|
||
code String @unique
|
||
telegramId String?
|
||
status CodeStatus @default(PENDING)
|
||
createdAt DateTime @default(now())
|
||
expiresAt DateTime
|
||
usedAt DateTime?
|
||
|
||
@@index([code])
|
||
@@index([telegramId])
|
||
}
|
||
|
||
enum CodeStatus {
|
||
PENDING
|
||
CLAIMED
|
||
USED
|
||
EXPIRED
|
||
}
|