mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-05-15 22:37:32 -04:00
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:
27
mealie/db/fixes/fix_slug_foods.py
Normal file
27
mealie/db/fixes/fix_slug_foods.py
Normal 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)
|
||||
Reference in New Issue
Block a user