Fix/fix slug names (#1026)

* fix food seeder to use value instead of keys

* fix all recipe names being slugified

* add helper path utilities

* add fix script for database to rename foods

* add safe calling for fixes
This commit is contained in:
Hayden
2022-03-09 09:18:33 -09:00
committed by GitHub
parent de6fd9472d
commit 2d1ef7173d
8 changed files with 57 additions and 3 deletions

View File

@@ -0,0 +1,27 @@
import json
from mealie.core import root_logger
from mealie.repos.repository_factory import AllRepositories
from mealie.repos.seed.resources import foods as food_resources
def fix_slug_food_names(db: AllRepositories):
check_for_food = "dairy-products-and-dairy-substitutes"
food = db.ingredient_foods.get_one(check_for_food, "name")
logger = root_logger.get_logger("init_db")
if not food:
logger.info("No food found with slug: '{}' skipping fix".format(check_for_food))
return
all_foods = db.ingredient_foods.get_all()
seed_foods: dict[str, str] = json.loads(food_resources.en_us.read_text())
for food in all_foods:
if food.name in seed_foods:
food.name = seed_foods[food.name]
logger.info("Updating food: {}".format(food.name))
db.ingredient_foods.update(food.id, food)