N-FIN-42: add default category column to entity

This commit is contained in:
Markus Thielker 2024-03-17 11:31:17 +01:00
parent 74bb618706
commit 5556901115
No known key found for this signature in database
2 changed files with 17 additions and 7 deletions

View file

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

View file

@ -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")