generator client { provider = "prisma-client-js" } datasource db { provider = "mysql" url = env("DATABASE_URL") } model Product { id Int @id @default(autoincrement()) name String normalizedName String @unique category String? canonicalName String? isActive Boolean @default(true) deletedAt DateTime? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt inventoryItems InventoryItem[] recipeIngredients RecipeIngredient[] pantryItems PantryItem[] receiptAliases ReceiptAlias[] } model InventoryItem { id Int @id @default(autoincrement()) productId Int quantity Decimal @db.Decimal(10, 2) unit String brand String? location String? priority Int? purchaseDate DateTime? opened Boolean? shelfNote String? suitableFor String? isOnSale Boolean? priceLevel Int? bestBeforeDate DateTime? proteinType String? isLeftover Boolean? comment String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt product Product @relation(fields: [productId], references: [id], onDelete: Cascade) consumptions InventoryConsumption[] @@index([productId]) } model InventoryConsumption { id Int @id @default(autoincrement()) inventoryItem InventoryItem @relation(fields: [inventoryItemId], references: [id]) inventoryItemId Int amountUsed Decimal @db.Decimal(10, 2) comment String? createdAt DateTime @default(now()) } model Recipe { id Int @id @default(autoincrement()) name String description String? @db.Text instructions String? @db.Text imageUrl String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt ingredients RecipeIngredient[] mealPlanEntries MealPlanEntry[] } model RecipeIngredient { id Int @id @default(autoincrement()) recipe Recipe @relation(fields: [recipeId], references: [id]) recipeId Int product Product @relation(fields: [productId], references: [id]) productId Int quantity Decimal @db.Decimal(10, 2) unit String note String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt } model PantryItem { id Int @id @default(autoincrement()) productId Int @unique product Product @relation(fields: [productId], references: [id], onDelete: Cascade) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt } model ReceiptAlias { id Int @id @default(autoincrement()) receiptName String @unique // normaliserat kvittonamn (lowercase, trim) productId Int product Product @relation(fields: [productId], references: [id], onDelete: Cascade) createdAt DateTime @default(now()) } model MealPlanEntry { id Int @id @default(autoincrement()) date DateTime @db.Date recipe Recipe @relation(fields: [recipeId], references: [id], onDelete: Cascade) recipeId Int createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@unique([date]) @@index([date]) }