Files
wrong-notebook/prisma/schema.prisma

138 lines
4.0 KiB
Plaintext

// 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"
binaryTargets = ["native", "linux-musl-openssl-3.0.x"]
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model User {
id String @id @default(cuid())
email String @unique
password String
name String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
educationStage String? // primary, junior_high, senior_high, university
enrollmentYear Int?
role String @default("user") // "admin" or "user"
isActive Boolean @default(true) // 用户是否启用
errorItems ErrorItem[]
subjects Subject[]
practiceRecords PracticeRecord[]
customTags KnowledgeTag[] // User's custom tags
}
// 统一知识点标签表 (支持无限层级)
model KnowledgeTag {
id String @id @default(cuid())
name String // 标签名,如 "勾股定理"
subject String // 学科,如 "math", "english"
// 层级控制 (邻接表模式)
parentId String?
parent KnowledgeTag? @relation("TagHierarchy", fields: [parentId], references: [id])
children KnowledgeTag[] @relation("TagHierarchy")
// 排序与编码
order Int @default(0) // 用于保持教材顺序
code String? // 如 "1.2.1"
// 区分系统预设 vs 用户自定义
isSystem Boolean @default(false)
userId String? // 如果是用户自定义标签,绑定 userId
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
// 与错题的多对多关系
errorItems ErrorItem[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// 联合索引:确保同一用户(或系统)下同一学科的标签名不重复
@@unique([subject, name, userId])
// 索引:加速父子查询
@@index([parentId])
@@index([subject])
}
model Subject {
id String @id @default(cuid())
name String
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
errorItems ErrorItem[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([name, userId])
}
model ErrorItem {
id String @id @default(cuid())
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
subjectId String?
subject Subject? @relation(fields: [subjectId], references: [id], onDelete: Cascade)
originalImageUrl String
ocrText String?
// AI Analysis
questionText String? // Parsed question
answerText String? // AI provided answer
analysis String? // AI analysis/explanation
knowledgePoints String? // [DEPRECATED] JSON string - kept for migration only
// New: many-to-many relation with KnowledgeTag
tags KnowledgeTag[]
// User Metadata
source String? // e.g. "Midterm Exam"
errorType String? // e.g. "Calculation", "Concept"
userNotes String?
masteryLevel Int @default(0) // 0: New, 1: Reviewing, 2: Mastered
gradeSemester String? // e.g. "Junior High Grade 2, 1st Semester"
paperLevel String? // e.g. "A", "B", "Other"
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
reviewSchedules ReviewSchedule[]
}
model ReviewSchedule {
id String @id @default(cuid())
errorItemId String
errorItem ErrorItem @relation(fields: [errorItemId], references: [id], onDelete: Cascade)
scheduledFor DateTime
completedAt DateTime?
isCorrect Boolean? // Result of the review
createdAt DateTime @default(now())
}
model PracticeRecord {
id String @id @default(cuid())
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
subject String? // e.g. "Math", "Physics"
difficulty String? // "easy", "medium", "hard", "harder"
isCorrect Boolean?
createdAt DateTime @default(now())
}