Don't allow self referencing parent product definitions (API) (references #2973)

This commit is contained in:
Bernd Bestel 2026-08-27 20:34:50 +02:00
parent 744b3b020c
commit c179fc0fbd
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300

25
migrations/0257.sql Normal file
View File

@ -0,0 +1,25 @@
-- Remove all self referencing parent product definitions
UPDATE products
SET parent_product_id = null
WHERE id = parent_product_id;
CREATE TRIGGER prevent_self_referenced_parent_product_INS AFTER INSERT ON products
BEGIN
SELECT CASE WHEN((
SELECT 1
FROM products p
WHERE p.id = NEW.id
AND p.id = p.parent_product_id
)
NOTNULL) THEN RAISE(ABORT, 'A product cannot reference itself as a parent product') END;
END;
CREATE TRIGGER prevent_self_referenced_parent_product_UPD AFTER UPDATE ON products
BEGIN
SELECT CASE WHEN((
SELECT 1
FROM products p
WHERE p.id = NEW.id
AND p.id = p.parent_product_id
) NOTNULL) THEN RAISE(ABORT, 'A product cannot reference itself as a parent product') END;
END;