Files
wrong-notebook/prisma/schema.prisma
lypher24 2ab46198e0 feat: 增加错因分析字段与重新解答同步 (#69)
- 为错题记录增加错误解答原文、错因分析、作答状态字段
- 增加对应 Prisma 数据库迁移
- AI 识题结果中解析并保存错因分析相关字段
- 新增/编辑/详情/列表接口支持错因字段
- 前端支持查看和编辑作答状态、错误解答原文、错因分析
- 列表卡片显示作答状态,并支持搜索错误解答和错因分析
- 重新解答时同步重新生成答案、解析、知识点和错因字段
- 重新解答时有原图就带原图,便于判断学生手写过程
- 收紧重新解答提示词,避免 AI 猜测不可见的学生错因
- 修正“只填写错因分析时不应强制改成做错了”的状态逻辑
- 补充提示词、Azure 解析、错因状态、重新解答请求相关单元测试

注意:
- 拉取或部署后需要执行 Prisma 数据库迁移

Co-authored-by: Codex <codex@local>
Co-authored-by: wttwins <104707749+wttwins@users.noreply.github.com>
2026-04-30 21:44:28 +08:00

141 lines
4.2 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], onDelete: SetNull)
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, parentId])
// 索引:加速父子查询
@@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
wrongAnswerText String? // Student's wrong answer/work if visible
mistakeAnalysis String? // Analysis of why the wrong answer happened
mistakeStatus String? // not_attempted, wrong_attempt, unknown
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())
}