Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create ExerciseComment database table #2404

Merged
merged 11 commits into from
Oct 19, 2022
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;
flacial marked this conversation as resolved.
Show resolved Hide resolved
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;
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 ExerciseComments[]
flacial marked this conversation as resolved.
Show resolved Hide resolved

@@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 ExerciseComments[]

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

@@map("exerciseSubmissions")
}

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

}