Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- CreateTable
CREATE TABLE "Discussion" (
"id" SERIAL NOT NULL,
"createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ(6) NOT NULL,
"authorId" INTEGER NOT NULL,
"exerciseId" INTEGER NOT NULL,
"userPic" TEXT NOT NULL,
"content" TEXT NOT NULL,
"parentId" INTEGER,

CONSTRAINT "Discussion_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "Discussion" ADD CONSTRAINT "Discussion_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Discussion" ADD CONSTRAINT "Discussion_exerciseId_fkey" FOREIGN KEY ("exerciseId") REFERENCES "exercises"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Discussion" ADD CONSTRAINT "Discussion_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "Discussion"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Discussion" ALTER COLUMN "userPic" DROP NOT NULL;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting userPic to not null, since not every user may have uploaded a profile picture

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- DropForeignKey
ALTER TABLE "Discussion" DROP CONSTRAINT "Discussion_authorId_fkey";

-- AddForeignKey
ALTER TABLE "Discussion" ADD CONSTRAINT "Discussion_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
40 changes: 40 additions & 0 deletions prisma/migrations/20221014185321_exercise_comments/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Warnings:

- You are about to drop the `Discussion` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropForeignKey
ALTER TABLE "Discussion" DROP CONSTRAINT "Discussion_authorId_fkey";

-- DropForeignKey
ALTER TABLE "Discussion" DROP CONSTRAINT "Discussion_exerciseId_fkey";

-- DropForeignKey
ALTER TABLE "Discussion" DROP CONSTRAINT "Discussion_parentId_fkey";

-- DropTable
DROP TABLE "Discussion";

-- CreateTable
CREATE TABLE "ExerciseComments" (
"id" SERIAL NOT NULL,
"createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ(6) NOT NULL,
"authorId" INTEGER NOT NULL,
"exerciseId" INTEGER NOT NULL,
"userPic" TEXT,
"content" TEXT NOT NULL,
"parentId" INTEGER,

CONSTRAINT "ExerciseComments_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "ExerciseComments" ADD CONSTRAINT "ExerciseComments_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ExerciseComments" ADD CONSTRAINT "ExerciseComments_exerciseId_fkey" FOREIGN KEY ("exerciseId") REFERENCES "exercises"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ExerciseComments" ADD CONSTRAINT "ExerciseComments_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "ExerciseComments"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Warnings:

- You are about to drop the `ExerciseComments` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropForeignKey
ALTER TABLE "ExerciseComments" DROP CONSTRAINT "ExerciseComments_authorId_fkey";

-- DropForeignKey
ALTER TABLE "ExerciseComments" DROP CONSTRAINT "ExerciseComments_exerciseId_fkey";

-- DropForeignKey
ALTER TABLE "ExerciseComments" DROP CONSTRAINT "ExerciseComments_parentId_fkey";

-- DropTable
DROP TABLE "ExerciseComments";

-- CreateTable
CREATE TABLE "ExerciseComment" (
"id" SERIAL NOT NULL,
"createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ(6) NOT NULL,
"authorId" INTEGER NOT NULL,
"exerciseId" INTEGER NOT NULL,
"userPic" TEXT,
"content" TEXT NOT NULL,
"parentId" INTEGER,

CONSTRAINT "ExerciseComment_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "ExerciseComment" ADD CONSTRAINT "ExerciseComment_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ExerciseComment" ADD CONSTRAINT "ExerciseComment_exerciseId_fkey" FOREIGN KEY ("exerciseId") REFERENCES "exercises"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ExerciseComment" ADD CONSTRAINT "ExerciseComment_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "ExerciseComment"("id") ON DELETE SET NULL ON UPDATE CASCADE;
50 changes: 34 additions & 16 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ model User {
submissionsReviewed Submission[] @relation("userReviewedSubmissions")
submissions Submission[] @relation("userSubmissions")
userLessons UserLesson[]
exerciseComments ExerciseComment[]

@@map("users")
}
Expand All @@ -177,22 +178,23 @@ model Module {
}

model Exercise {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @updatedAt @db.Timestamptz(6)
authorId Int
moduleId Int
description String
answer String
testStr String?
explanation String?
flagReason String?
flaggedAt DateTime?
flaggedById Int?
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
flaggedBy User? @relation("flaggedExercises", fields: [flaggedById], references: [id])
module Module @relation(fields: [moduleId], references: [id], onDelete: Cascade)
submissions ExerciseSubmission[]
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @updatedAt @db.Timestamptz(6)
authorId Int
moduleId Int
description String
answer String
testStr String?
explanation String?
flagReason String?
flaggedAt DateTime?
flaggedById Int?
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
flaggedBy User? @relation("flaggedExercises", fields: [flaggedById], references: [id])
module Module @relation(fields: [moduleId], references: [id], onDelete: Cascade)
submissions ExerciseSubmission[]
exerciseComments ExerciseComment[]

@@map("exercises")
}
Expand All @@ -207,3 +209,19 @@ model ExerciseSubmission {

@@map("exerciseSubmissions")
}

model ExerciseComment {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @updatedAt @db.Timestamptz(6)
authorId Int
exerciseId Int
userPic String?
content String
parentId Int?
exercise Exercise @relation(fields: [exerciseId], references: [id], onDelete: Cascade)
author User @relation(fields: [authorId], references: [id], onDelete: SetNull)
parent ExerciseComment? @relation("ExerciseCommentReplies", fields: [parentId], references: [id])
replies ExerciseComment[] @relation("ExerciseCommentReplies")

}