feat(prisma/schema): add multilingual support for problem descriptions and solutions

BREAKING CHANGE:
- Removed `description` and `solution` fields from Problem model
- Added new models `ProblemDescription` and `ProblemSolution` with language support (EN/ZH)
- Updated seed data structure to support multilingual content
- Requires database migration and data migration from old structure
This commit is contained in:
cfngc4594 2025-05-07 21:04:46 +08:00
parent f0beb69b2c
commit cfbbdbf821

View File

@ -30,8 +30,8 @@ model User {
// Optional for WebAuthn support // Optional for WebAuthn support
Authenticator Authenticator[] Authenticator Authenticator[]
role Role @default(GUEST) role Role @default(GUEST)
problems Problem[] problems Problem[]
submissions Submission[] submissions Submission[]
createdAt DateTime @default(now()) createdAt DateTime @default(now())
@ -45,25 +45,60 @@ enum Difficulty {
} }
model Problem { model Problem {
id String @id @default(cuid()) id String @id @default(cuid())
displayId Int @unique displayId Int @unique
title String titles ProblemTitle[]
description String descriptions ProblemDescription[]
solution String solutions ProblemSolution[]
difficulty Difficulty @default(EASY) difficulty Difficulty @default(EASY)
published Boolean @default(false) published Boolean @default(false)
userId String userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade) user User @relation(fields: [userId], references: [id], onDelete: Cascade)
timeLimit Int @default(1000) timeLimit Int @default(1000)
memoryLimit Int @default(128) memoryLimit Int @default(128)
templates Template[] templates Template[]
testcases Testcase[] testcases Testcase[]
submissions Submission[] submissions Submission[]
@@index([userId]) @@index([userId])
@@index([difficulty]) @@index([difficulty])
} }
enum Language {
en
zh
}
model ProblemTitle {
id String @id @default(cuid())
language Language
content String
problemId String
problem Problem @relation(fields: [problemId], references: [id], onDelete: Cascade)
@@unique([problemId, language])
}
model ProblemDescription {
id String @id @default(cuid())
language Language
content String
problemId String
problem Problem @relation(fields: [problemId], references: [id], onDelete: Cascade)
@@unique([problemId, language])
}
model ProblemSolution {
id String @id @default(cuid())
language Language
content String
problemId String
problem Problem @relation(fields: [problemId], references: [id], onDelete: Cascade)
@@unique([problemId, language])
}
enum EditorLanguage { enum EditorLanguage {
c c
cpp cpp
@ -148,11 +183,11 @@ model Submission {
} }
model Testcase { model Testcase {
id String @id @default(cuid()) id String @id @default(cuid())
problemId String problemId String
problem Problem @relation(fields: [problemId], references: [id], onDelete: Cascade) problem Problem @relation(fields: [problemId], references: [id], onDelete: Cascade)
data TestcaseData[] data TestcaseData[]
expectedOutput String expectedOutput String
testcaseResults TestcaseResult[] testcaseResults TestcaseResult[]
} }