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

feat: Add flag columns to Exercise #1993

Merged
3 changes: 3 additions & 0 deletions prisma/migrations/20220616205126_exercise_flag/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "exercises" ADD COLUMN "flagReason" TEXT,
ADD COLUMN "flagged" BOOLEAN;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
Warnings:

- You are about to drop the column `flagged` on the `exercises` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "exercises" DROP COLUMN "flagged",
ADD COLUMN "flaggedAt" TIMESTAMP(3);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "exercises" ADD COLUMN "flaggedById" INTEGER;

-- AddForeignKey
ALTER TABLE "exercises" ADD FOREIGN KEY ("flaggedById") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
15 changes: 10 additions & 5 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ model User {
modules Module[]
exercises Exercise[]

Exercise Exercise[] @relation("flaggedBy")
Copy link
Member

Choose a reason for hiding this comment

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

Something like flaggedExercises will be a more suitable and descriptive name for this field.

@@map("users")
}

Expand All @@ -176,17 +177,21 @@ model Module {
}

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

@@map("exercises")
}