feat: make pantry items and meal plan entries user-scoped; update related services and controllers

This commit is contained in:
Nils-Johan Gynther
2026-04-22 18:38:04 +02:00
parent 44b4e7ad73
commit 4482129fca
6 changed files with 123 additions and 35 deletions
@@ -0,0 +1,25 @@
-- PantryItem: make user-scoped
ALTER TABLE `PantryItem` ADD COLUMN `userId` INTEGER NULL;
UPDATE `PantryItem`
SET `userId` = (SELECT `id` FROM `User` ORDER BY `id` ASC LIMIT 1)
WHERE `userId` IS NULL;
ALTER TABLE `PantryItem` DROP INDEX `PantryItem_productId_key`;
ALTER TABLE `PantryItem` MODIFY `userId` INTEGER NOT NULL;
ALTER TABLE `PantryItem` ADD INDEX `PantryItem_userId_idx`(`userId`);
ALTER TABLE `PantryItem` ADD UNIQUE INDEX `PantryItem_userId_productId_key`(`userId`, `productId`);
ALTER TABLE `PantryItem` ADD CONSTRAINT `PantryItem_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- MealPlanEntry: make user-scoped
ALTER TABLE `MealPlanEntry` ADD COLUMN `userId` INTEGER NULL;
UPDATE `MealPlanEntry`
SET `userId` = (SELECT `id` FROM `User` ORDER BY `id` ASC LIMIT 1)
WHERE `userId` IS NULL;
ALTER TABLE `MealPlanEntry` DROP INDEX `MealPlanEntry_date_key`;
ALTER TABLE `MealPlanEntry` MODIFY `userId` INTEGER NOT NULL;
ALTER TABLE `MealPlanEntry` ADD INDEX `MealPlanEntry_userId_idx`(`userId`);
ALTER TABLE `MealPlanEntry` ADD UNIQUE INDEX `MealPlanEntry_userId_date_key`(`userId`, `date`);
ALTER TABLE `MealPlanEntry` ADD CONSTRAINT `MealPlanEntry_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;