mirror of
https://github.com/grocy/grocy.git
synced 2026-10-17 13:19:19 +02:00
Don't allow self referencing parent product definitions (API) (references #2973)
This commit is contained in:
parent
744b3b020c
commit
c179fc0fbd
25
migrations/0257.sql
Normal file
25
migrations/0257.sql
Normal 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;
|
||||
Loading…
Reference in New Issue
Block a user