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;