Delete QU conversions when deleting QU (theoretical problem, closes #1796)

This commit is contained in:
Bernd Bestel
2022-02-20 19:18:10 +01:00
parent 777fcbae77
commit 5bfdddd52b

10
migrations/0171.sql Normal file
View File

@@ -0,0 +1,10 @@
CREATE TRIGGER remove_conversions AFTER DELETE ON quantity_units
BEGIN
DELETE FROM quantity_unit_conversions
WHERE from_qu_id = OLD.id
OR to_qu_id = OLD.id;
END;
DELETE FROM quantity_unit_conversions
WHERE NOT EXISTS(SELECT 1 FROM quantity_units WHERE id = quantity_unit_conversions.from_qu_id)
OR NOT EXISTS(SELECT 1 FROM quantity_units WHERE id = quantity_unit_conversions.to_qu_id);