-- Ensure L3 "Kvarg & Cottage cheese" exists in both dairy branches:
-- 1) Mejeri, ost & ägg > Allergi mejeri
-- 2) Mejeri, ost & ägg > Kvarg & Cottage cheese

-- Branch 1: under Allergi mejeri
INSERT INTO `Category` (`name`, `parentId`)
SELECT 'Kvarg & Cottage cheese', c2.id
FROM `Category` c1
JOIN `Category` c2
  ON c2.parentId = c1.id
  AND c2.name = 'Allergi mejeri'
LEFT JOIN `Category` c3
  ON c3.parentId = c2.id
  AND c3.name = 'Kvarg & Cottage cheese'
WHERE c1.name = 'Mejeri, ost & ägg'
  AND c1.parentId IS NULL
  AND c3.id IS NULL;

-- Branch 2: under standard Kvarg & Cottage cheese branch
INSERT INTO `Category` (`name`, `parentId`)
SELECT 'Kvarg & Cottage cheese', c2.id
FROM `Category` c1
JOIN `Category` c2
  ON c2.parentId = c1.id
  AND c2.name = 'Kvarg & Cottage cheese'
LEFT JOIN `Category` c3
  ON c3.parentId = c2.id
  AND c3.name = 'Kvarg & Cottage cheese'
WHERE c1.name = 'Mejeri, ost & ägg'
  AND c1.parentId IS NULL
  AND c3.id IS NULL;
