feat: implement user-scoped receipt aliases with global fallback; enhance alias management in admin panel
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
-- Make receipt aliases user-scoped with optional admin-managed global fallback.
|
||||
ALTER TABLE `ReceiptAlias`
|
||||
ADD COLUMN `ownerId` INT NULL,
|
||||
ADD COLUMN `isGlobal` BOOLEAN NOT NULL DEFAULT false;
|
||||
|
||||
-- Existing aliases become global aliases.
|
||||
UPDATE `ReceiptAlias`
|
||||
SET `isGlobal` = true
|
||||
WHERE `isGlobal` = false;
|
||||
|
||||
-- Replace previous global unique key on receiptName.
|
||||
ALTER TABLE `ReceiptAlias`
|
||||
DROP INDEX `ReceiptAlias_receiptName_key`;
|
||||
|
||||
-- Add scoped uniqueness and lookup indexes.
|
||||
ALTER TABLE `ReceiptAlias`
|
||||
ADD UNIQUE INDEX `ReceiptAlias_receiptName_ownerId_isGlobal_key`(`receiptName`, `ownerId`, `isGlobal`),
|
||||
ADD INDEX `ReceiptAlias_ownerId_idx`(`ownerId`),
|
||||
ADD INDEX `ReceiptAlias_isGlobal_idx`(`isGlobal`);
|
||||
|
||||
-- Link aliases to owner when user-scoped.
|
||||
ALTER TABLE `ReceiptAlias`
|
||||
ADD CONSTRAINT `ReceiptAlias_ownerId_fkey`
|
||||
FOREIGN KEY (`ownerId`) REFERENCES `User`(`id`)
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -26,6 +26,7 @@ model User {
|
||||
ownedProducts Product[]
|
||||
pantryItems PantryItem[]
|
||||
mealPlanEntries MealPlanEntry[]
|
||||
receiptAliases ReceiptAlias[]
|
||||
}
|
||||
|
||||
model Product {
|
||||
@@ -175,10 +176,17 @@ model PantryItem {
|
||||
|
||||
model ReceiptAlias {
|
||||
id Int @id @default(autoincrement())
|
||||
receiptName String @unique // normaliserat kvittonamn (lowercase, trim)
|
||||
receiptName String // normaliserat kvittonamn (lowercase, trim)
|
||||
ownerId Int?
|
||||
owner User? @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
||||
isGlobal Boolean @default(false)
|
||||
productId Int
|
||||
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@unique([receiptName, ownerId, isGlobal])
|
||||
@@index([ownerId])
|
||||
@@index([isGlobal])
|
||||
}
|
||||
|
||||
model MealPlanEntry {
|
||||
|
||||
Reference in New Issue
Block a user