From 606221dab34f9fac23274d2e9e001b8bf9000452 Mon Sep 17 00:00:00 2001 From: Supan Adit Pratama Date: Sat, 2 Nov 2024 09:13:32 +0700 Subject: [PATCH] feat: relation migration for sample custom relation support --- prisma/migrations/20241102021258_init/migration.sql | 11 +++++++++++ prisma/schema.prisma | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 prisma/migrations/20241102021258_init/migration.sql diff --git a/prisma/migrations/20241102021258_init/migration.sql b/prisma/migrations/20241102021258_init/migration.sql new file mode 100644 index 0000000..ee71cc0 --- /dev/null +++ b/prisma/migrations/20241102021258_init/migration.sql @@ -0,0 +1,11 @@ +-- CreateTable +CREATE TABLE "todo" ( + "id" UUID NOT NULL DEFAULT gen_random_uuid(), + "name" TEXT NOT NULL, + "user_id" UUID NOT NULL, + + CONSTRAINT "todo_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "todo" ADD CONSTRAINT "todo_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "account"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ebdd7d1..44cee97 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -18,6 +18,16 @@ datasource db { model User { id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid name String + Todo Todo[] @@map("account") } + +model Todo { + id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid + name String + user User @relation(fields: [userId], references: [id]) + userId String @map("user_id") @db.Uuid + + @@map("todo") +}