From c179fc0fbdfb77a0fce702ff062dcde19fe34e60 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Thu, 27 Aug 2026 20:34:50 +0200 Subject: [PATCH] Don't allow self referencing parent product definitions (API) (references #2973) --- migrations/0257.sql | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 migrations/0257.sql diff --git a/migrations/0257.sql b/migrations/0257.sql new file mode 100644 index 00000000..26f2fa95 --- /dev/null +++ b/migrations/0257.sql @@ -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;