grocy/migrations/0108.sql
fipwmaqzufheoxq92ebc 923e027a4b
Some bug fixes. (#959)
* Fixes #956. Return 404 for missing objects in GenericEntityApiController.php

* Fixes #936 and #943. Include Products that expire today in /stock/volatile and "Expiring soon"-sum on stockoverview

* Fixes #881. Remove items of deleted shopping lists.

* Fixes #875. Prevent infinite nested recipes.

* Review

Co-authored-by: Bernd Bestel <bernd@berrnd.de>
2020-08-22 09:58:25 +02:00

28 lines
974 B
SQL

DELETE FROM shopping_list
WHERE shopping_list_id NOT IN (SELECT id FROM shopping_lists);
CREATE TRIGGER remove_items_from_deleted_shopping_list AFTER DELETE ON shopping_lists
BEGIN
DELETE FROM shopping_list WHERE shopping_list_id = OLD.id;
END;
CREATE TRIGGER prevent_infinite_nested_recipes_INS BEFORE INSERT ON recipes_nestings
BEGIN
SELECT CASE WHEN((
SELECT 1
FROM recipes_nestings_resolved rnr
WHERE NEW.recipe_id = rnr.includes_recipe_id
AND NEW.includes_recipe_id = rnr.recipe_id
) NOTNULL) THEN RAISE(ABORT, "Recursive nested recipe detected") END;
END;
CREATE TRIGGER prevent_infinite_nested_recipes_UPD BEFORE UPDATE ON recipes_nestings
BEGIN
SELECT CASE WHEN((
SELECT 1
FROM recipes_nestings_resolved rnr
WHERE NEW.recipe_id = rnr.includes_recipe_id
AND NEW.includes_recipe_id = rnr.recipe_id
) NOTNULL) THEN RAISE(ABORT, "Recursive nested recipe detected") END;
END;