From d47d6466a86a82acc546ea078e4a24aecf6477ab Mon Sep 17 00:00:00 2001 From: Nils-Johan Gynther Date: Sun, 3 May 2026 11:38:38 +0200 Subject: [PATCH] fix(deploy): update seed script references to use full seed_all.sql --- db/seeds/seed_all.sql | 65 +++++++++++++++++++++++++++++++++++++++++++ deploy.sh | 10 +++---- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/db/seeds/seed_all.sql b/db/seeds/seed_all.sql index 3be604d4..73895ee6 100644 --- a/db/seeds/seed_all.sql +++ b/db/seeds/seed_all.sql @@ -513,3 +513,68 @@ INSERT INTO `Category` (`name`, `parentId`) SELECT 'Frysta skaldjur & havsdelikatesser', c2.id FROM `Category` c1 JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Skaldjur & Havsdelikatesser' WHERE c1.name = 'Fisk & Skaldjur' AND c1.parentId IS NULL; + + +-- ============================================================ +-- STEG 3: ÅTERKOPPLA Product.categoryId EFTER KATEGORI-RESET +-- +-- Matchningsordning (från mest specifik till minst specifik): +-- 1) Product.category = nivå 2, Product.subcategory = nivå 3 +-- 2) Product.category = nivå 1, Product.subcategory = nivå 3 +-- 3) Product.category = nivå 1, Product.subcategory = nivå 2 +-- 4) Product.category = nivå 1 (fallback) +-- +-- Obs: Vi sätter bara categoryId där den fortfarande är NULL. +-- ============================================================ + +-- 1) category (nivå 2) + subcategory (nivå 3) +UPDATE `Product` p +JOIN `Category` c1 ON c1.parentId IS NULL +JOIN `Category` c2 ON c2.parentId = c1.id +JOIN `Category` c3 ON c3.parentId = c2.id +SET p.`categoryId` = c3.id +WHERE p.`categoryId` IS NULL + AND p.`category` IS NOT NULL + AND p.`subcategory` IS NOT NULL + AND LOWER(TRIM(p.`category`)) = LOWER(TRIM(c2.`name`)) + AND LOWER(TRIM(p.`subcategory`)) = LOWER(TRIM(c3.`name`)); + +-- 2) category (nivå 1) + subcategory (nivå 3) +UPDATE `Product` p +JOIN `Category` c1 ON c1.parentId IS NULL +JOIN `Category` c2 ON c2.parentId = c1.id +JOIN `Category` c3 ON c3.parentId = c2.id +SET p.`categoryId` = c3.id +WHERE p.`categoryId` IS NULL + AND p.`category` IS NOT NULL + AND p.`subcategory` IS NOT NULL + AND LOWER(TRIM(p.`category`)) = LOWER(TRIM(c1.`name`)) + AND LOWER(TRIM(p.`subcategory`)) = LOWER(TRIM(c3.`name`)); + +-- 3) category (nivå 1) + subcategory (nivå 2) +UPDATE `Product` p +JOIN `Category` c1 ON c1.parentId IS NULL +JOIN `Category` c2 ON c2.parentId = c1.id +SET p.`categoryId` = c2.id +WHERE p.`categoryId` IS NULL + AND p.`category` IS NOT NULL + AND p.`subcategory` IS NOT NULL + AND LOWER(TRIM(p.`category`)) = LOWER(TRIM(c1.`name`)) + AND LOWER(TRIM(p.`subcategory`)) = LOWER(TRIM(c2.`name`)); + +-- 4) fallback: category (nivå 1) +UPDATE `Product` p +JOIN `Category` c1 ON c1.parentId IS NULL +SET p.`categoryId` = c1.id +WHERE p.`categoryId` IS NULL + AND p.`category` IS NOT NULL + AND LOWER(TRIM(p.`category`)) = LOWER(TRIM(c1.`name`)); + +-- Summering efter återkoppling +SELECT COUNT(*) AS products_with_category_id +FROM `Product` +WHERE `categoryId` IS NOT NULL; + +SELECT COUNT(*) AS products_without_category_id +FROM `Product` +WHERE `categoryId` IS NULL; diff --git a/deploy.sh b/deploy.sh index 1242b674..18aad1d9 100755 --- a/deploy.sh +++ b/deploy.sh @@ -26,7 +26,7 @@ docker compose -f compose.yml -f compose.flutter.yml build echo "Startar tjänster..." docker compose -f compose.yml -f compose.flutter.yml up -d -echo "Kör kategori-seed..." +echo "Kör full seed (seed_all.sql)..." MARIADB_ROOT_PASSWORD=$(grep MARIADB_ROOT_PASSWORD .env | cut -d '=' -f2 | tr -d '"' | tr -d "'") MARIADB_DATABASE=$(grep MARIADB_DATABASE .env | cut -d '=' -f2 | tr -d '"' | tr -d "'") @@ -39,12 +39,12 @@ for i in $(seq 1 30); do sleep 2 done -if [ -f "db/seeds/categories_supplement.sql" ]; then +if [ -f "db/seeds/seed_all.sql" ]; then docker exec -i recipe-db mariadb -uroot -p"$MARIADB_ROOT_PASSWORD" "$MARIADB_DATABASE" \ - < db/seeds/categories_supplement.sql - echo "Kategori-seed klar." + < db/seeds/seed_all.sql + echo "Full seed klar." else - echo "Ingen categories_supplement.sql hittades — hoppar över seed." + echo "Ingen db/seeds/seed_all.sql hittades — hoppar över seed." fi echo "Status:"