mirror of
https://github.com/grocy/grocy.git
synced 2026-04-07 05:16:15 +02:00
Review
This commit is contained in:
parent
1110793a88
commit
6d594dfd72
|
|
@ -1,16 +1,11 @@
|
||||||
DELETE
|
DELETE FROM shopping_list
|
||||||
FROM shopping_list
|
|
||||||
WHERE shopping_list_id NOT IN (SELECT id FROM shopping_lists);
|
WHERE shopping_list_id NOT IN (SELECT id FROM shopping_lists);
|
||||||
|
|
||||||
CREATE TRIGGER remove_items_from_deleted_shopping_list
|
CREATE TRIGGER remove_items_from_deleted_shopping_list AFTER DELETE ON shopping_lists
|
||||||
AFTER DELETE
|
|
||||||
ON shopping_lists
|
|
||||||
BEGIN
|
BEGIN
|
||||||
DELETE FROM shopping_list WHERE shopping_list_id = OLD.id;
|
DELETE FROM shopping_list WHERE shopping_list_id = OLD.id;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
DROP TRIGGER IF EXISTS prevent_infinite_nested_recipes_INS;
|
|
||||||
|
|
||||||
CREATE TRIGGER prevent_infinite_nested_recipes_INS BEFORE INSERT ON recipes_nestings
|
CREATE TRIGGER prevent_infinite_nested_recipes_INS BEFORE INSERT ON recipes_nestings
|
||||||
BEGIN
|
BEGIN
|
||||||
SELECT CASE WHEN((
|
SELECT CASE WHEN((
|
||||||
|
|
@ -18,11 +13,9 @@ BEGIN
|
||||||
FROM recipes_nestings_resolved rnr
|
FROM recipes_nestings_resolved rnr
|
||||||
WHERE NEW.recipe_id = rnr.includes_recipe_id
|
WHERE NEW.recipe_id = rnr.includes_recipe_id
|
||||||
AND NEW.includes_recipe_id = rnr.recipe_id
|
AND NEW.includes_recipe_id = rnr.recipe_id
|
||||||
)
|
) NOTNULL) THEN RAISE(ABORT, "Recursive nested recipe detected") END;
|
||||||
NOTNULL) THEN RAISE(ABORT, "Recursive nested recipe detected") END;
|
|
||||||
END;
|
END;
|
||||||
|
|
||||||
DROP TRIGGER IF EXISTS prevent_infinite_nested_recipes_UPD;
|
|
||||||
CREATE TRIGGER prevent_infinite_nested_recipes_UPD BEFORE UPDATE ON recipes_nestings
|
CREATE TRIGGER prevent_infinite_nested_recipes_UPD BEFORE UPDATE ON recipes_nestings
|
||||||
BEGIN
|
BEGIN
|
||||||
SELECT CASE WHEN((
|
SELECT CASE WHEN((
|
||||||
|
|
@ -30,23 +23,5 @@ BEGIN
|
||||||
FROM recipes_nestings_resolved rnr
|
FROM recipes_nestings_resolved rnr
|
||||||
WHERE NEW.recipe_id = rnr.includes_recipe_id
|
WHERE NEW.recipe_id = rnr.includes_recipe_id
|
||||||
AND NEW.includes_recipe_id = rnr.recipe_id
|
AND NEW.includes_recipe_id = rnr.recipe_id
|
||||||
)
|
) NOTNULL) THEN RAISE(ABORT, "Recursive nested recipe detected") END;
|
||||||
NOTNULL) THEN RAISE(ABORT, "Recursive nested recipe detected") END;
|
|
||||||
END;
|
END;
|
||||||
|
|
||||||
DROP VIEW recipes_nestings_resolved;
|
|
||||||
CREATE VIEW recipes_nestings_resolved
|
|
||||||
AS
|
|
||||||
WITH RECURSIVE r1(recipe_id, includes_recipe_id, includes_servings)
|
|
||||||
AS (
|
|
||||||
SELECT id, id, 1
|
|
||||||
FROM recipes
|
|
||||||
|
|
||||||
UNION ALL
|
|
||||||
|
|
||||||
SELECT rn.recipe_id, r1.includes_recipe_id, rn.servings
|
|
||||||
FROM recipes_nestings rn, r1 r1
|
|
||||||
WHERE rn.includes_recipe_id = r1.recipe_id
|
|
||||||
)
|
|
||||||
SELECT recipe_id AS id, recipe_id, includes_recipe_id, includes_servings
|
|
||||||
FROM r1;
|
|
||||||
Loading…
Reference in New Issue
Block a user