From 5556901115070970f08859445741290966265bda Mon Sep 17 00:00:00 2001 From: Markus Thielker Date: Sun, 17 Mar 2024 11:31:17 +0100 Subject: [PATCH] N-FIN-42: add default category column to entity --- .../migration.sql | 7 +++++++ prisma/schema.prisma | 17 ++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 prisma/migrations/20240317102723_add_default_category_to_entity/migration.sql diff --git a/prisma/migrations/20240317102723_add_default_category_to_entity/migration.sql b/prisma/migrations/20240317102723_add_default_category_to_entity/migration.sql new file mode 100644 index 0000000..f7767eb --- /dev/null +++ b/prisma/migrations/20240317102723_add_default_category_to_entity/migration.sql @@ -0,0 +1,7 @@ +-- AlterTable +ALTER TABLE "entities" + ADD COLUMN "default_category_id" INTEGER; + +-- AddForeignKey +ALTER TABLE "entities" + ADD CONSTRAINT "entities_default_category_id_fkey" FOREIGN KEY ("default_category_id") REFERENCES "categories" ("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5d51152..1e9f6e1 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -34,13 +34,15 @@ model Session { } model Entity { - id Int @id @default(autoincrement()) - userId String @map("user_id") - user User @relation(fields: [userId], references: [id]) - name String - type EntityType - createdAt DateTime @default(now()) @map("created_at") - updatedAt DateTime @updatedAt @map("updated_at") + id Int @id @default(autoincrement()) + userId String @map("user_id") + user User @relation(fields: [userId], references: [id]) + name String + type EntityType + defaultCategory Category? @relation(fields: [defaultCategoryId], references: [id]) + defaultCategoryId Int? @map("default_category_id") + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") paymentsAsPayor Payment[] @relation("PayorEntity") paymentsAsPayee Payment[] @relation("PayeeEntity") @@ -84,6 +86,7 @@ model Category { updatedAt DateTime @updatedAt @map("updated_at") payments Payment[] + Entity Entity[] @@unique(fields: [userId, name]) @@map("categories")