diff --git a/foodlib/migrations/20241108122437_fix_recipe_name_null.sql b/foodlib/migrations/20241108122437_fix_recipe_name_null.sql new file mode 100644 index 0000000..0be62d9 --- /dev/null +++ b/foodlib/migrations/20241108122437_fix_recipe_name_null.sql @@ -0,0 +1,36 @@ +-- Add migration script here +CREATE OR REPLACE VIEW public.event_ingredients_before_prep_time_resolve AS + SELECT events.event_id, + events.event_name AS event, + event_meals.recipe_id, + recipes.name as recipe, + event_meals.place_id, + places.name AS place, + event_meals.start_time, + event_meals.end_time, + resolved_recipes.ingredient_id, + resolved_recipes.ingredient, + resolved_recipes.weight * recipe_multipliers.recipe_multiplier * ingredient_weight.weight AS weight, + recipe_multipliers.recipe_multiplier * resolved_recipes.weight * ingredients.energy * 1000::numeric AS energy, + ingredient_sources.price * (recipe_multipliers.recipe_multiplier * resolved_recipes.weight / (ingredient_weight.weight * COALESCE(ingredient_sources.package_size, 1::numeric)))::double precision AS price, + event_meals.servings, + event_meals.meal_id, + resolved_recipes.acc AS subrecipe_hierarchy, + event_meals.start_time AS buy_by, + ingredient_sources.store_id + FROM events + LEFT JOIN event_meals USING (event_id) + LEFT JOIN places USING (place_id) + LEFT JOIN resolved_recipes USING (recipe_id) + LEFT JOIN recipes USING (recipe_id) + LEFT JOIN ingredients USING (ingredient_id) + LEFT JOIN best_event_ingredient_sources USING (event_id, ingredient_id) + LEFT JOIN ingredient_sources USING (ingredient_source_id, ingredient_id) + LEFT JOIN ingredient_weight USING (ingredient_id, unit_id) + LEFT JOIN ( SELECT event_meals_1.recipe_id, + event_meals_1.event_id, + event_meals_1.place_id, + event_meals_1.start_time, + event_meals_1.energy_per_serving * event_meals_1.servings::numeric / recipe_stats.energy AS recipe_multiplier + FROM event_meals event_meals_1 + JOIN recipe_stats USING (recipe_id)) recipe_multipliers USING (event_id, recipe_id, place_id, start_time) \ No newline at end of file diff --git a/foodlib/src/meals.rs b/foodlib/src/meals.rs index 1dc7bc2..1102805 100644 --- a/foodlib/src/meals.rs +++ b/foodlib/src/meals.rs @@ -77,9 +77,9 @@ impl FoodBase { place as "place!", event_meals.start_time as "start_time!", event_meals.end_time as "end_time!", - round(sum(weight),2) as "weight!", - (CASE WHEN event_meals.servings != 0 THEN round(sum(energy) / event_meals.servings,0) ELSE 0 END) as "energy!", - sum(price) as "price!", + COALESCE(round(sum(weight),2),0) as "weight!", + COALESCE((CASE WHEN event_meals.servings != 0 THEN round(sum(energy) / event_meals.servings,0) ELSE 0 END),0) as "energy!", + COALESCE(sum(price),'0'::float8::numeric::money) as "price!", event_meals.servings as "servings!" FROM event_ingredients @@ -109,9 +109,9 @@ impl FoodBase { place as "place!", event_meals.start_time as "start_time!", event_meals.end_time as "end_time!", - round(sum(weight),2) as "weight!", - (CASE WHEN event_meals.servings != 0 THEN round(sum(energy) / event_meals.servings,0) ELSE 0 END) as "energy!", - sum(price) as "price!", + COALESCE(round(sum(weight),2),0) as "weight!", + COALESCE((CASE WHEN event_meals.servings != 0 THEN round(sum(energy) / event_meals.servings,0) ELSE 0 END),0) as "energy!", + COALESCE(sum(price),'0'::float8::numeric::money) as "price!", event_meals.servings as "servings!" FROM event_ingredients