Add StudentQuestion and StudentQuestionMessage models
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "QuestionStatus" AS ENUM ('OPEN', 'CLOSED');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "StudentQuestion" (
|
||||
"id" TEXT NOT NULL,
|
||||
"userId" TEXT NOT NULL,
|
||||
"courseId" TEXT,
|
||||
"title" TEXT NOT NULL,
|
||||
"status" "QuestionStatus" NOT NULL DEFAULT 'OPEN',
|
||||
"closedAt" TIMESTAMP(3),
|
||||
"closedById" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "StudentQuestion_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "StudentQuestionMessage" (
|
||||
"id" TEXT NOT NULL,
|
||||
"questionId" TEXT NOT NULL,
|
||||
"authorId" TEXT NOT NULL,
|
||||
"text" TEXT NOT NULL,
|
||||
"files" JSONB,
|
||||
"isRead" BOOLEAN NOT NULL DEFAULT false,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "StudentQuestionMessage_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "StudentQuestion" ADD CONSTRAINT "StudentQuestion_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "StudentQuestion" ADD CONSTRAINT "StudentQuestion_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "Course"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "StudentQuestion" ADD CONSTRAINT "StudentQuestion_closedById_fkey" FOREIGN KEY ("closedById") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "StudentQuestionMessage" ADD CONSTRAINT "StudentQuestionMessage_questionId_fkey" FOREIGN KEY ("questionId") REFERENCES "StudentQuestion"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "StudentQuestionMessage" ADD CONSTRAINT "StudentQuestionMessage_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -37,6 +37,9 @@ model User {
|
||||
accessLogs AccessLog[] @relation("AccessLogUser")
|
||||
adminAccessLogs AccessLog[] @relation("AccessLogAdmin")
|
||||
balanceTransactions BalanceTransaction[]
|
||||
questions StudentQuestion[]
|
||||
closedQuestions StudentQuestion[] @relation("QuestionClosedBy")
|
||||
questionMessages StudentQuestionMessage[]
|
||||
}
|
||||
|
||||
model Session {
|
||||
@@ -111,6 +114,7 @@ model Course {
|
||||
modules Module[]
|
||||
enrollments CourseEnrollment[]
|
||||
accessLogs AccessLog[]
|
||||
questions StudentQuestion[]
|
||||
}
|
||||
|
||||
model Module {
|
||||
@@ -312,6 +316,45 @@ model LessonComment {
|
||||
replies LessonComment[] @relation("CommentReplies")
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// Student Questions
|
||||
// ─────────────────────────────────────────────
|
||||
|
||||
enum QuestionStatus {
|
||||
OPEN
|
||||
CLOSED
|
||||
}
|
||||
|
||||
model StudentQuestion {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
courseId String?
|
||||
title String
|
||||
status QuestionStatus @default(OPEN)
|
||||
closedAt DateTime?
|
||||
closedById String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
course Course? @relation(fields: [courseId], references: [id], onDelete: SetNull)
|
||||
closedBy User? @relation("QuestionClosedBy", fields: [closedById], references: [id], onDelete: SetNull)
|
||||
messages StudentQuestionMessage[]
|
||||
}
|
||||
|
||||
model StudentQuestionMessage {
|
||||
id String @id @default(cuid())
|
||||
questionId String
|
||||
authorId String
|
||||
text String
|
||||
files Json? // [{name, url, size}]
|
||||
isRead Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
question StudentQuestion @relation(fields: [questionId], references: [id], onDelete: Cascade)
|
||||
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// Balance
|
||||
// ─────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user