mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Created database logic for nested recipes (references #77)
This commit is contained in:
parent
78865a9d3c
commit
3de3e03ab3
25
migrations/0043.sql
Normal file
25
migrations/0043.sql
Normal file
@ -0,0 +1,25 @@
|
||||
CREATE TABLE recipes_nestings (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
recipe_id INTEGER NOT NULL,
|
||||
includes_recipe_id INTEGER NOT NULL,
|
||||
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime')),
|
||||
|
||||
UNIQUE(recipe_id, includes_recipe_id)
|
||||
);
|
||||
|
||||
CREATE VIEW recipes_nestings_resolved
|
||||
AS
|
||||
WITH RECURSIVE r1(recipe_id, includes_recipe_id)
|
||||
AS (
|
||||
SELECT id, id
|
||||
FROM recipes
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT rn.recipe_id, r1.includes_recipe_id
|
||||
FROM recipes_nestings rn, r1 r1
|
||||
WHERE rn.includes_recipe_id = r1.recipe_id
|
||||
LIMIT 100 -- This is just a safety limit to prevent infinite loops due to infinite nested recipes
|
||||
)
|
||||
SELECT *
|
||||
FROM r1;
|
Loading…
x
Reference in New Issue
Block a user