mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-09 03:04:54 -04:00
fix: Migration Issue With Duplicate Labels (#3085)
* fixed eager queries * test --------- Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com>
This commit is contained in:
parent
c3f7ad8954
commit
7947aa99ae
@ -59,7 +59,12 @@ def _resolve_duplicate_food(
|
||||
keep_food_id: UUID4,
|
||||
dupe_food_id: UUID4,
|
||||
):
|
||||
for shopping_list_item in session.query(ShoppingListItem).filter_by(food_id=dupe_food_id).all():
|
||||
for shopping_list_item in (
|
||||
session.query(ShoppingListItem)
|
||||
.options(load_only(ShoppingListItem.id, ShoppingListItem.food_id))
|
||||
.filter_by(food_id=dupe_food_id)
|
||||
.all()
|
||||
):
|
||||
shopping_list_item.food_id = keep_food_id
|
||||
|
||||
for recipe_ingredient in (
|
||||
@ -82,10 +87,20 @@ def _resolve_duplicate_unit(
|
||||
keep_unit_id: UUID4,
|
||||
dupe_unit_id: UUID4,
|
||||
):
|
||||
for shopping_list_item in session.query(ShoppingListItem).filter_by(unit_id=dupe_unit_id).all():
|
||||
for shopping_list_item in (
|
||||
session.query(ShoppingListItem)
|
||||
.options(load_only(ShoppingListItem.id, ShoppingListItem.unit_id))
|
||||
.filter_by(unit_id=dupe_unit_id)
|
||||
.all()
|
||||
):
|
||||
shopping_list_item.unit_id = keep_unit_id
|
||||
|
||||
for recipe_ingredient in session.query(RecipeIngredientModel).filter_by(unit_id=dupe_unit_id).all():
|
||||
for recipe_ingredient in (
|
||||
session.query(RecipeIngredientModel)
|
||||
.options(load_only(RecipeIngredientModel.id, RecipeIngredientModel.unit_id))
|
||||
.filter_by(unit_id=dupe_unit_id)
|
||||
.all()
|
||||
):
|
||||
recipe_ingredient.unit_id = keep_unit_id
|
||||
|
||||
session.commit()
|
||||
@ -100,10 +115,20 @@ def _resolve_duplicate_label(
|
||||
keep_label_id: UUID4,
|
||||
dupe_label_id: UUID4,
|
||||
):
|
||||
for shopping_list_item in session.query(ShoppingListItem).filter_by(label_id=dupe_label_id).all():
|
||||
for shopping_list_item in (
|
||||
session.query(ShoppingListItem)
|
||||
.options(load_only(ShoppingListItem.id, ShoppingListItem.label_id))
|
||||
.filter_by(label_id=dupe_label_id)
|
||||
.all()
|
||||
):
|
||||
shopping_list_item.label_id = keep_label_id
|
||||
|
||||
for ingredient_food in session.query(IngredientFoodModel).filter_by(label_id=dupe_label_id).all():
|
||||
for ingredient_food in (
|
||||
session.query(IngredientFoodModel)
|
||||
.options(load_only(IngredientFoodModel.id, IngredientFoodModel.label_id))
|
||||
.filter_by(label_id=dupe_label_id)
|
||||
.all()
|
||||
):
|
||||
ingredient_food.label_id = keep_label_id
|
||||
|
||||
session.commit()
|
||||
|
@ -13,6 +13,9 @@ backup_version_44e8d670719d_2 = CWD / "backups/backup_version_44e8d670719d_2.zip
|
||||
backup_version_44e8d670719d_3 = CWD / "backups/backup_version_44e8d670719d_3.zip"
|
||||
"""44e8d670719d: add extras to shopping lists, list items, and ingredient foods"""
|
||||
|
||||
backup_version_44e8d670719d_4 = CWD / "backups/backup_version_44e8d670719d_4.zip"
|
||||
"""44e8d670719d: add extras to shopping lists, list items, and ingredient foods"""
|
||||
|
||||
backup_version_ba1e4a6cfe99_1 = CWD / "backups/backup_version_ba1e4a6cfe99_1.zip"
|
||||
"""ba1e4a6cfe99: added plural names and alias tables for foods and units"""
|
||||
|
||||
|
BIN
tests/data/backups/backup_version_44e8d670719d_4.zip
Normal file
BIN
tests/data/backups/backup_version_44e8d670719d_4.zip
Normal file
Binary file not shown.
@ -74,6 +74,7 @@ def test_database_restore():
|
||||
test_data.backup_version_44e8d670719d_1,
|
||||
test_data.backup_version_44e8d670719d_2,
|
||||
test_data.backup_version_44e8d670719d_3,
|
||||
test_data.backup_version_44e8d670719d_4,
|
||||
test_data.backup_version_ba1e4a6cfe99_1,
|
||||
test_data.backup_version_bcfdad6b7355_1,
|
||||
],
|
||||
@ -81,6 +82,7 @@ def test_database_restore():
|
||||
"44e8d670719d_1: add extras to shopping lists, list items, and ingredient foods",
|
||||
"44e8d670719d_2: add extras to shopping lists, list items, and ingredient foods",
|
||||
"44e8d670719d_3: add extras to shopping lists, list items, and ingredient foods",
|
||||
"44e8d670719d_4: add extras to shopping lists, list items, and ingredient foods",
|
||||
"ba1e4a6cfe99_1: added plural names and alias tables for foods and units",
|
||||
"bcfdad6b7355_1: remove tool name and slug unique contraints",
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user