From 5f6b9261f23c93610ec566b91c880f6b680a707e Mon Sep 17 00:00:00 2001 From: Nils-Johan Gynther Date: Wed, 15 Apr 2026 21:32:16 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20ers=C3=A4tt=20partial=20migration=20med?= =?UTF-8?q?=20fullst=C3=A4ndigt=20initial=20schema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migration.sql | 94 ++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/backend/prisma/migrations/20260415000000_add_recipe_image_url/migration.sql b/backend/prisma/migrations/20260415000000_add_recipe_image_url/migration.sql index 2b1fc752..b39fd69c 100644 --- a/backend/prisma/migrations/20260415000000_add_recipe_image_url/migration.sql +++ b/backend/prisma/migrations/20260415000000_add_recipe_image_url/migration.sql @@ -1,2 +1,92 @@ --- Migration: add imageUrl to Recipe -ALTER TABLE `Recipe` ADD COLUMN `imageUrl` VARCHAR(191) NULL; +-- CreateTable +CREATE TABLE `Product` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `name` VARCHAR(191) NOT NULL, + `normalizedName` VARCHAR(191) NOT NULL, + `category` VARCHAR(191) NULL, + `canonicalName` VARCHAR(191) NULL, + `isActive` BOOLEAN NOT NULL DEFAULT true, + `deletedAt` DATETIME(3) NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + + UNIQUE INDEX `Product_normalizedName_key`(`normalizedName`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `InventoryItem` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `productId` INTEGER NOT NULL, + `quantity` DECIMAL(10, 2) NOT NULL, + `unit` VARCHAR(191) NOT NULL, + `brand` VARCHAR(191) NULL, + `location` VARCHAR(191) NULL, + `priority` INTEGER NULL, + `purchaseDate` DATETIME(3) NULL, + `opened` BOOLEAN NULL, + `shelfNote` VARCHAR(191) NULL, + `suitableFor` VARCHAR(191) NULL, + `isOnSale` BOOLEAN NULL, + `priceLevel` INTEGER NULL, + `bestBeforeDate` DATETIME(3) NULL, + `proteinType` VARCHAR(191) NULL, + `isLeftover` BOOLEAN NULL, + `comment` VARCHAR(191) NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + + INDEX `InventoryItem_productId_idx`(`productId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `InventoryConsumption` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `inventoryItemId` INTEGER NOT NULL, + `amountUsed` DECIMAL(10, 2) NOT NULL, + `comment` VARCHAR(191) NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Recipe` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `name` VARCHAR(191) NOT NULL, + `description` VARCHAR(191) NULL, + `instructions` TEXT NULL, + `imageUrl` VARCHAR(191) NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `RecipeIngredient` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `recipeId` INTEGER NOT NULL, + `productId` INTEGER NOT NULL, + `quantity` DECIMAL(10, 2) NOT NULL, + `unit` VARCHAR(191) NOT NULL, + `note` VARCHAR(191) NULL, + `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updatedAt` DATETIME(3) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- AddForeignKey +ALTER TABLE `InventoryItem` ADD CONSTRAINT `InventoryItem_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Product`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `InventoryConsumption` ADD CONSTRAINT `InventoryConsumption_inventoryItemId_fkey` FOREIGN KEY (`inventoryItemId`) REFERENCES `InventoryItem`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `RecipeIngredient` ADD CONSTRAINT `RecipeIngredient_recipeId_fkey` FOREIGN KEY (`recipeId`) REFERENCES `Recipe`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `RecipeIngredient` ADD CONSTRAINT `RecipeIngredient_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Product`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; +