-- Karotte: Debug-Tempo und Preis an gleiche Basis wie andere Kat.-1-Waren (siehe initializeFalukantPredefines.js).
-- Sicher für alle Installationen: nur production_time ohne optionale Spalten.

BEGIN;

UPDATE falukant_type.product
SET production_time = 2
WHERE label_tr = 'carrot';

COMMIT;

-- Optional (wenn Migration mit original_sell_cost läuft): in derselben Session ausführen
/*
UPDATE falukant_type.product
SET original_sell_cost = 6
WHERE label_tr = 'carrot';

WITH RECURSIVE ancestors AS (
  SELECT id AS start_id, id, parent_id, tax_percent FROM falukant_data.region
  UNION ALL
  SELECT a.start_id, r.id, r.parent_id, r.tax_percent
  FROM falukant_data.region r
  JOIN ancestors a ON r.id = a.parent_id
), totals AS (
  SELECT start_id, COALESCE(SUM(tax_percent), 0) AS total FROM ancestors GROUP BY start_id
), mm AS (
  SELECT COALESCE(MAX(total), 0) AS max_total FROM totals
)
UPDATE falukant_type.product p
SET sell_cost = CEIL(p.original_sell_cost * (
  CASE WHEN (1 - mm.max_total / 100) <= 0 THEN 1 ELSE (1 / (1 - mm.max_total / 100)) END
))
FROM mm
WHERE p.label_tr = 'carrot' AND p.original_sell_cost IS NOT NULL;
*/

-- Ohne original_sell_cost: grob sell_cost = 6 (wie Milch/Brot; ggf. anpassen)
-- UPDATE falukant_type.product SET sell_cost = 6 WHERE label_tr = 'carrot';
