feat: relation migration for sample custom relation support

This commit is contained in:
Supan Adit Pratama 2024-11-02 09:13:32 +07:00
parent 5c083f3add
commit 606221dab3
2 changed files with 21 additions and 0 deletions

View File

@ -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;

View File

@ -18,6 +18,16 @@ datasource db {
model User { model User {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String name String
Todo Todo[]
@@map("account") @@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")
}