diff --git a/prisma/migrations/20221006161259_create_discussions_table/migration.sql b/prisma/migrations/20221006161259_create_discussions_table/migration.sql new file mode 100644 index 000000000..bdfc22ffe --- /dev/null +++ b/prisma/migrations/20221006161259_create_discussions_table/migration.sql @@ -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; diff --git a/prisma/migrations/20221006161545_create_discussions_table2/migration.sql b/prisma/migrations/20221006161545_create_discussions_table2/migration.sql new file mode 100644 index 000000000..0a8b29178 --- /dev/null +++ b/prisma/migrations/20221006161545_create_discussions_table2/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Discussion" ALTER COLUMN "userPic" DROP NOT NULL; diff --git a/prisma/migrations/20221006163340_create_discussions_table3/migration.sql b/prisma/migrations/20221006163340_create_discussions_table3/migration.sql new file mode 100644 index 000000000..57a66578e --- /dev/null +++ b/prisma/migrations/20221006163340_create_discussions_table3/migration.sql @@ -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; diff --git a/prisma/migrations/20221014185321_exercise_comments/migration.sql b/prisma/migrations/20221014185321_exercise_comments/migration.sql new file mode 100644 index 000000000..7b0e80265 --- /dev/null +++ b/prisma/migrations/20221014185321_exercise_comments/migration.sql @@ -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; diff --git a/prisma/migrations/20221016154350_change_exercise_comments_to_exercise_comment/migration.sql b/prisma/migrations/20221016154350_change_exercise_comments_to_exercise_comment/migration.sql new file mode 100644 index 000000000..590ceb82a --- /dev/null +++ b/prisma/migrations/20221016154350_change_exercise_comments_to_exercise_comment/migration.sql @@ -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; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 87103c790..a4167003f 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -156,6 +156,7 @@ model User { submissionsReviewed Submission[] @relation("userReviewedSubmissions") submissions Submission[] @relation("userSubmissions") userLessons UserLesson[] + exerciseComments ExerciseComment[] @@map("users") } @@ -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") } @@ -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") + +}