Init monorepo: Frontend + Backend
This commit is contained in:
100
survey-backend/prisma/schema.prisma
Normal file
100
survey-backend/prisma/schema.prisma
Normal file
@@ -0,0 +1,100 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
// --- МОДЕЛИ ---
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
email String @unique
|
||||
password String // Хеш пароля
|
||||
name String?
|
||||
inviteCode String @unique // Уникальный код типа "#USER-1234"
|
||||
|
||||
surveys Survey[] @relation("CreatedSurveys") // Опросы, которые я создал
|
||||
submissions Submission[] // Опросы, которые я прошел
|
||||
|
||||
allowedIn AllowedAccess[] // Куда меня пригласили
|
||||
}
|
||||
|
||||
model Survey {
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
description String?
|
||||
isPublished Boolean @default(false)
|
||||
accessType AccessType @default(PUBLIC) // PUBLIC, INVITE_ONLY
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
authorId Int
|
||||
author User @relation("CreatedSurveys", fields: [authorId], references: [id])
|
||||
|
||||
questions Question[]
|
||||
submissions Submission[]
|
||||
allowedUsers AllowedAccess[]
|
||||
}
|
||||
|
||||
enum AccessType {
|
||||
PUBLIC
|
||||
INVITE_ONLY
|
||||
}
|
||||
|
||||
model Question {
|
||||
id Int @id @default(autoincrement())
|
||||
surveyId Int
|
||||
survey Survey @relation(fields: [surveyId], references: [id], onDelete: Cascade)
|
||||
|
||||
text String
|
||||
type QuestionType @default(SINGLE)
|
||||
points Int @default(0)
|
||||
order Int @default(0)
|
||||
|
||||
options Option[]
|
||||
}
|
||||
|
||||
enum QuestionType {
|
||||
SINGLE // Один выбор (Radio)
|
||||
MULTI // Множественный (Checkbox)
|
||||
// TEXT - можно добавить позже
|
||||
}
|
||||
|
||||
model Option {
|
||||
id Int @id @default(autoincrement())
|
||||
questionId Int
|
||||
question Question @relation(fields: [questionId], references: [id], onDelete: Cascade)
|
||||
|
||||
text String
|
||||
isCorrect Boolean @default(false) // Правильный ли это ответ?
|
||||
}
|
||||
|
||||
// Белый список для приватных опросов
|
||||
model AllowedAccess {
|
||||
id Int @id @default(autoincrement())
|
||||
surveyId Int
|
||||
userId Int
|
||||
|
||||
// ДОБАВЛЕНО: onDelete: Cascade
|
||||
survey Survey @relation(fields: [surveyId], references: [id], onDelete: Cascade)
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
|
||||
@@unique([surveyId, userId])
|
||||
}
|
||||
|
||||
// Результаты прохождения
|
||||
model Submission {
|
||||
id Int @id @default(autoincrement())
|
||||
surveyId Int
|
||||
userId Int?
|
||||
|
||||
score Int
|
||||
maxScore Int
|
||||
completedAt DateTime @default(now())
|
||||
|
||||
// ДОБАВЛЕНО: onDelete: Cascade
|
||||
survey Survey @relation(fields: [surveyId], references: [id], onDelete: Cascade)
|
||||
user User? @relation(fields: [userId], references: [id])
|
||||
}
|
||||
Reference in New Issue
Block a user