Skip to content

Commit ccb6f47

Browse files
authored
Merge pull request #2404 from HS-90/discussions-backend
Create Discussions table in Prisma
2 parents c0e1f96 + 9bacfc3 commit ccb6f47

File tree

6 files changed

+143
-16
lines changed

6 files changed

+143
-16
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- CreateTable
2+
CREATE TABLE "Discussion" (
3+
"id" SERIAL NOT NULL,
4+
"createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
5+
"updatedAt" TIMESTAMPTZ(6) NOT NULL,
6+
"authorId" INTEGER NOT NULL,
7+
"exerciseId" INTEGER NOT NULL,
8+
"userPic" TEXT NOT NULL,
9+
"content" TEXT NOT NULL,
10+
"parentId" INTEGER,
11+
12+
CONSTRAINT "Discussion_pkey" PRIMARY KEY ("id")
13+
);
14+
15+
-- AddForeignKey
16+
ALTER TABLE "Discussion" ADD CONSTRAINT "Discussion_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
17+
18+
-- AddForeignKey
19+
ALTER TABLE "Discussion" ADD CONSTRAINT "Discussion_exerciseId_fkey" FOREIGN KEY ("exerciseId") REFERENCES "exercises"("id") ON DELETE CASCADE ON UPDATE CASCADE;
20+
21+
-- AddForeignKey
22+
ALTER TABLE "Discussion" ADD CONSTRAINT "Discussion_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "Discussion"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "Discussion" ALTER COLUMN "userPic" DROP NOT NULL;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- DropForeignKey
2+
ALTER TABLE "Discussion" DROP CONSTRAINT "Discussion_authorId_fkey";
3+
4+
-- AddForeignKey
5+
ALTER TABLE "Discussion" ADD CONSTRAINT "Discussion_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the `Discussion` table. If the table is not empty, all the data it contains will be lost.
5+
6+
*/
7+
-- DropForeignKey
8+
ALTER TABLE "Discussion" DROP CONSTRAINT "Discussion_authorId_fkey";
9+
10+
-- DropForeignKey
11+
ALTER TABLE "Discussion" DROP CONSTRAINT "Discussion_exerciseId_fkey";
12+
13+
-- DropForeignKey
14+
ALTER TABLE "Discussion" DROP CONSTRAINT "Discussion_parentId_fkey";
15+
16+
-- DropTable
17+
DROP TABLE "Discussion";
18+
19+
-- CreateTable
20+
CREATE TABLE "ExerciseComments" (
21+
"id" SERIAL NOT NULL,
22+
"createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
23+
"updatedAt" TIMESTAMPTZ(6) NOT NULL,
24+
"authorId" INTEGER NOT NULL,
25+
"exerciseId" INTEGER NOT NULL,
26+
"userPic" TEXT,
27+
"content" TEXT NOT NULL,
28+
"parentId" INTEGER,
29+
30+
CONSTRAINT "ExerciseComments_pkey" PRIMARY KEY ("id")
31+
);
32+
33+
-- AddForeignKey
34+
ALTER TABLE "ExerciseComments" ADD CONSTRAINT "ExerciseComments_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
35+
36+
-- AddForeignKey
37+
ALTER TABLE "ExerciseComments" ADD CONSTRAINT "ExerciseComments_exerciseId_fkey" FOREIGN KEY ("exerciseId") REFERENCES "exercises"("id") ON DELETE CASCADE ON UPDATE CASCADE;
38+
39+
-- AddForeignKey
40+
ALTER TABLE "ExerciseComments" ADD CONSTRAINT "ExerciseComments_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "ExerciseComments"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the `ExerciseComments` table. If the table is not empty, all the data it contains will be lost.
5+
6+
*/
7+
-- DropForeignKey
8+
ALTER TABLE "ExerciseComments" DROP CONSTRAINT "ExerciseComments_authorId_fkey";
9+
10+
-- DropForeignKey
11+
ALTER TABLE "ExerciseComments" DROP CONSTRAINT "ExerciseComments_exerciseId_fkey";
12+
13+
-- DropForeignKey
14+
ALTER TABLE "ExerciseComments" DROP CONSTRAINT "ExerciseComments_parentId_fkey";
15+
16+
-- DropTable
17+
DROP TABLE "ExerciseComments";
18+
19+
-- CreateTable
20+
CREATE TABLE "ExerciseComment" (
21+
"id" SERIAL NOT NULL,
22+
"createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
23+
"updatedAt" TIMESTAMPTZ(6) NOT NULL,
24+
"authorId" INTEGER NOT NULL,
25+
"exerciseId" INTEGER NOT NULL,
26+
"userPic" TEXT,
27+
"content" TEXT NOT NULL,
28+
"parentId" INTEGER,
29+
30+
CONSTRAINT "ExerciseComment_pkey" PRIMARY KEY ("id")
31+
);
32+
33+
-- AddForeignKey
34+
ALTER TABLE "ExerciseComment" ADD CONSTRAINT "ExerciseComment_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
35+
36+
-- AddForeignKey
37+
ALTER TABLE "ExerciseComment" ADD CONSTRAINT "ExerciseComment_exerciseId_fkey" FOREIGN KEY ("exerciseId") REFERENCES "exercises"("id") ON DELETE CASCADE ON UPDATE CASCADE;
38+
39+
-- AddForeignKey
40+
ALTER TABLE "ExerciseComment" ADD CONSTRAINT "ExerciseComment_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "ExerciseComment"("id") ON DELETE SET NULL ON UPDATE CASCADE;

prisma/schema.prisma

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ model User {
156156
submissionsReviewed Submission[] @relation("userReviewedSubmissions")
157157
submissions Submission[] @relation("userSubmissions")
158158
userLessons UserLesson[]
159+
exerciseComments ExerciseComment[]
159160
160161
@@map("users")
161162
}
@@ -177,22 +178,23 @@ model Module {
177178
}
178179

179180
model Exercise {
180-
id Int @id @default(autoincrement())
181-
createdAt DateTime @default(now()) @db.Timestamptz(6)
182-
updatedAt DateTime @updatedAt @db.Timestamptz(6)
183-
authorId Int
184-
moduleId Int
185-
description String
186-
answer String
187-
testStr String?
188-
explanation String?
189-
flagReason String?
190-
flaggedAt DateTime?
191-
flaggedById Int?
192-
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
193-
flaggedBy User? @relation("flaggedExercises", fields: [flaggedById], references: [id])
194-
module Module @relation(fields: [moduleId], references: [id], onDelete: Cascade)
195-
submissions ExerciseSubmission[]
181+
id Int @id @default(autoincrement())
182+
createdAt DateTime @default(now()) @db.Timestamptz(6)
183+
updatedAt DateTime @updatedAt @db.Timestamptz(6)
184+
authorId Int
185+
moduleId Int
186+
description String
187+
answer String
188+
testStr String?
189+
explanation String?
190+
flagReason String?
191+
flaggedAt DateTime?
192+
flaggedById Int?
193+
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
194+
flaggedBy User? @relation("flaggedExercises", fields: [flaggedById], references: [id])
195+
module Module @relation(fields: [moduleId], references: [id], onDelete: Cascade)
196+
submissions ExerciseSubmission[]
197+
exerciseComments ExerciseComment[]
196198
197199
@@map("exercises")
198200
}
@@ -207,3 +209,19 @@ model ExerciseSubmission {
207209
208210
@@map("exerciseSubmissions")
209211
}
212+
213+
model ExerciseComment {
214+
id Int @id @default(autoincrement())
215+
createdAt DateTime @default(now()) @db.Timestamptz(6)
216+
updatedAt DateTime @updatedAt @db.Timestamptz(6)
217+
authorId Int
218+
exerciseId Int
219+
userPic String?
220+
content String
221+
parentId Int?
222+
exercise Exercise @relation(fields: [exerciseId], references: [id], onDelete: Cascade)
223+
author User @relation(fields: [authorId], references: [id], onDelete: SetNull)
224+
parent ExerciseComment? @relation("ExerciseCommentReplies", fields: [parentId], references: [id])
225+
replies ExerciseComment[] @relation("ExerciseCommentReplies")
226+
227+
}

0 commit comments

Comments
 (0)