fix(deploy): update seed script references to use full seed_all.sql

This commit is contained in:
Nils-Johan Gynther
2026-05-03 11:38:38 +02:00
parent 70645232ab
commit d47d6466a8
2 changed files with 70 additions and 5 deletions
+65
View File
@@ -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;
+5 -5
View File
@@ -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:"