Optimized week recipe handling in mealplan (fixes #2168)

This commit is contained in:
Bernd Bestel
2023-04-01 22:04:30 +02:00
parent cc6b01de08
commit 71d44edb8c
5 changed files with 40 additions and 11 deletions

27
migrations/0217.sql Normal file
View File

@@ -0,0 +1,27 @@
DROP VIEW meal_plan_internal_recipe_relation;
CREATE VIEW meal_plan_internal_recipe_relation
AS
-- Relation between a meal plan (day) and the corresponding internal recipe(s)
SELECT mp.day, r.id AS recipe_id
FROM meal_plan mp
JOIN recipes r
ON r.name = CAST(mp.day AS TEXT)
AND r.type = 'mealplan-day'
UNION
SELECT mp.day, r.id AS recipe_id
FROM meal_plan mp
JOIN recipes r
ON r.name = LTRIM(STRFTIME('%Y-%W', mp.day), '0')
AND r.type = 'mealplan-week'
UNION
SELECT mp.day, r.id AS recipe_id
FROM meal_plan mp
JOIN recipes r
ON r.name = CAST(mp.day AS TEXT) || '#' || CAST(mp.id AS TEXT)
AND r.type = 'mealplan-shadow';