diff --git a/prisma/migrations/20220124135034_added_module/migration.sql b/prisma/migrations/20220124135034_added_module/migration.sql new file mode 100644 index 000000000..9933f60fb --- /dev/null +++ b/prisma/migrations/20220124135034_added_module/migration.sql @@ -0,0 +1,18 @@ +-- CreateTable +CREATE TABLE "modules" ( + "id" SERIAL NOT NULL, + "createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMPTZ(6) NOT NULL, + "authorId" INTEGER NOT NULL, + "lessonId" INTEGER NOT NULL, + "name" VARCHAR(255) NOT NULL, + "content" TEXT NOT NULL, + + PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "modules" ADD FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "modules" ADD FOREIGN KEY ("lessonId") REFERENCES "lessons"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 7811d8f08..6f9c79c2a 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -60,6 +60,7 @@ model Lesson { starLesson Star[] @relation("starLesson") submissions Submission[] userLessons UserLesson[] + modules Module[] @@map("lessons") } @@ -151,6 +152,21 @@ model User { submissions Submission[] @relation("userSubmissions") userLessons UserLesson[] comments Comment[] + modules Module[] @@map("users") } + +model Module { + 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 + lesson Lesson @relation(fields: [lessonId], references: [id]) + lessonId Int + name String @db.VarChar(255) + content String + + @@map("modules") +}