From e0b09f2bace7ec6c9612b195cfd2df3e975d278f Mon Sep 17 00:00:00 2001 From: tkt <37575408+tktcorporation@users.noreply.github.com> Date: Mon, 10 Oct 2022 10:07:14 +0000 Subject: [PATCH] :sparkles: finish https://redwoodjs.com/docs/tutorial/chapter6/comments-schema#running-the-migration --- .../20221010100550_create_comment/migration.sql | 13 +++++++++++++ api/db/schema.prisma | 10 ++++++++++ 2 files changed, 23 insertions(+) create mode 100644 api/db/migrations/20221010100550_create_comment/migration.sql diff --git a/api/db/migrations/20221010100550_create_comment/migration.sql b/api/db/migrations/20221010100550_create_comment/migration.sql new file mode 100644 index 000000000..26b8843ee --- /dev/null +++ b/api/db/migrations/20221010100550_create_comment/migration.sql @@ -0,0 +1,13 @@ +-- CreateTable +CREATE TABLE "Comment" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "body" TEXT NOT NULL, + "postId" INTEGER NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "Comment_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "Comment" ADD CONSTRAINT "Comment_postId_fkey" FOREIGN KEY ("postId") REFERENCES "Post"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/api/db/schema.prisma b/api/db/schema.prisma index c8f369290..ab28f23c6 100644 --- a/api/db/schema.prisma +++ b/api/db/schema.prisma @@ -12,6 +12,7 @@ model Post { id Int @id @default(autoincrement()) title String body String + comments Comment[] createdAt DateTime @default(now()) } @@ -32,3 +33,12 @@ model User { resetToken String? resetTokenExpiresAt DateTime? } + +model Comment { + id Int @id @default(autoincrement()) + name String + body String + post Post @relation(fields: [postId], references: [id]) + postId Int + createdAt DateTime @default(now()) +}