From 7bd6edfd7073a638e718bec04a244cd4dae79a1b Mon Sep 17 00:00:00 2001 From: Florian Sylvain Date: Fri, 27 Jan 2023 13:09:17 +0100 Subject: [PATCH] Added user_id on Category --- .../20230127120845_user_on_category/migration.sql | 11 +++++++++++ prisma/schema.prisma | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 prisma/migrations/20230127120845_user_on_category/migration.sql diff --git a/prisma/migrations/20230127120845_user_on_category/migration.sql b/prisma/migrations/20230127120845_user_on_category/migration.sql new file mode 100644 index 0000000..6fc75d1 --- /dev/null +++ b/prisma/migrations/20230127120845_user_on_category/migration.sql @@ -0,0 +1,11 @@ +/* + Warnings: + + - Added the required column `user_id` to the `Category` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE `Category` ADD COLUMN `user_id` INTEGER NOT NULL; + +-- AddForeignKey +ALTER TABLE `Category` ADD CONSTRAINT `Category_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 280fc3b..a9e3d37 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -8,7 +8,7 @@ datasource db { } model User { - id Int @id @default(autoincrement()) + id Int @id @default(autoincrement()) email String password String name String @@ -16,6 +16,7 @@ model User { created_at DateTime updated_at DateTime Snippet Snippet[] + Category Category[] } model Snippet { @@ -37,6 +38,8 @@ model Snippet { model Category { id Int @id @default(autoincrement()) name String + user_id Int + user User @relation(fields: [user_id], references: [id]) Snippet Snippet[] }