Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Move "on hand" and "last made" to household #4616

Open
wants to merge 56 commits into
base: mealie-next
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
3d7c776
add household to recipe relationship for last_made
michael-genson Nov 20, 2024
272f531
add household food/tool relationships
michael-genson Nov 20, 2024
d09e8b5
add migration
michael-genson Nov 20, 2024
2933484
rename relationship columns
michael-genson Nov 20, 2024
cfd1a78
updated food/tool models
michael-genson Nov 20, 2024
6417378
convert slugs back to relationships
michael-genson Nov 20, 2024
0dd1de1
added household recipe routes
michael-genson Nov 20, 2024
f51401e
updated recipe service set last made
michael-genson Nov 20, 2024
eab57b4
handle ordering by last made using household ordering
michael-genson Nov 20, 2024
fbd2dea
fix some import issues
michael-genson Nov 21, 2024
ce7180e
fix sqlalchemy warnings
michael-genson Nov 21, 2024
ea08778
more import issues
michael-genson Nov 21, 2024
a1b2ccf
dev:generate
michael-genson Nov 21, 2024
7d80243
fix return schema
michael-genson Nov 21, 2024
38ad4eb
remove unused onHand in recipe actions
michael-genson Nov 21, 2024
f0ad138
misc backend/schema fixes
michael-genson Nov 21, 2024
3e5b2f6
updated onHand logic in app
michael-genson Nov 21, 2024
eba94d4
use user-household last made timestamp
michael-genson Nov 22, 2024
468ab54
added migration scripts
michael-genson Nov 22, 2024
9e5dce0
fix list item sorting
michael-genson Nov 22, 2024
a483a9b
refactor and add migration to backup test
michael-genson Nov 22, 2024
9720c5d
Merge remote-tracking branch 'upstream/mealie-next' into feat/expand-…
michael-genson Nov 26, 2024
d6e1876
dev:generate (I'm so happy this works again)
michael-genson Nov 26, 2024
1628908
docs:gen
michael-genson Nov 26, 2024
155338d
better edge-case handling
michael-genson Nov 26, 2024
8129f45
added self service tests
michael-genson Nov 26, 2024
b056de8
update tests for last_made
michael-genson Nov 26, 2024
6911048
fix updating last made via task
michael-genson Nov 26, 2024
a5532f3
updated test
michael-genson Nov 26, 2024
25c3712
fix camelCase orderBy
michael-genson Nov 26, 2024
a688ec4
added order by lastMade test
michael-genson Nov 26, 2024
5318e8a
support custom columns on query
michael-genson Nov 26, 2024
1d7574c
refactor to use custom columns for rating and last made
michael-genson Nov 26, 2024
2154730
fix literal_column type and clean up namespace
michael-genson Nov 27, 2024
d08c4c5
simplify queries and move cast to repo
michael-genson Nov 27, 2024
d91a089
added tests
michael-genson Nov 27, 2024
49f71d4
made defaults less hardcoded
michael-genson Nov 27, 2024
69cfca5
lint
michael-genson Nov 27, 2024
8ffd644
added missing correlate statement for order_by
michael-genson Nov 27, 2024
fdc5d94
removed unused onHand attr
michael-genson Nov 27, 2024
598419b
removed unused onHand
michael-genson Nov 27, 2024
3855f7a
lint
michael-genson Nov 27, 2024
7aa4f11
update tests for mealplan timeline events
michael-genson Nov 27, 2024
4ad12b2
use column expressions instead of labels
michael-genson Nov 27, 2024
484573d
simplify implementation
michael-genson Nov 27, 2024
3e395fd
Merge branch 'mealie-next' into feat/expand-relationships-to-households
michael-genson Nov 27, 2024
43d5766
Merge branch 'mealie-next' into feat/expand-relationships-to-households
michael-genson Dec 2, 2024
2c60d37
Merge remote-tracking branch 'upstream/mealie-next' into feat/expand-…
michael-genson Dec 3, 2024
7848b84
modify recipe finder on_hand queries
michael-genson Dec 3, 2024
59c46d2
add/update tests
michael-genson Dec 3, 2024
5cfa638
Merge branch 'mealie-next' into feat/expand-relationships-to-households
michael-genson Dec 5, 2024
7e57759
move migration to new alembic folder
michael-genson Dec 5, 2024
95bd5c9
fix ruff lint rule
michael-genson Dec 5, 2024
ea2cff6
fix lint
michael-genson Dec 5, 2024
9390b6c
fix lint
michael-genson Dec 5, 2024
7772074
fix ruff thinking alembic is local package
michael-genson Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add household food/tool relationships
michael-genson committed Nov 20, 2024
commit 272f531f1761c432a4854b230128c132bdb44e8f
7 changes: 6 additions & 1 deletion mealie/db/models/household/household.py
Original file line number Diff line number Diff line change
@@ -8,11 +8,12 @@
from .._model_base import BaseMixins, SqlAlchemyBase
from .._model_utils.auto_init import auto_init
from .._model_utils.guid import GUID
from ..recipe import households_to_ingredient_foods, households_to_tools
from .household_to_recipe import HouseholdToRecipe

if TYPE_CHECKING:
from ..group import Group
from ..recipe import RecipeModel
from ..recipe import IngredientFoodModel, RecipeModel, Tool
from ..users import User
from . import (
CookBook,
@@ -67,6 +68,10 @@ class Household(SqlAlchemyBase, BaseMixins):
made_recipes: Mapped[list["RecipeModel"]] = orm.relationship(
"RecipeModel", secondary=HouseholdToRecipe.__tablename__, back_populates="made_by"
)
ingredient_foods: Mapped[list["IngredientFoodModel"]] = orm.relationship(
"IngredientFoodModel", secondary=households_to_ingredient_foods, back_populates="households"
)
tools: Mapped[list["Tool"]] = orm.relationship("Tool", secondary=households_to_tools, back_populates="households")

model_config = ConfigDict(
exclude={
17 changes: 16 additions & 1 deletion mealie/db/models/recipe/ingredient.py
Original file line number Diff line number Diff line change
@@ -14,6 +14,16 @@

if TYPE_CHECKING:
from ..group import Group
from ..household import Household


households_to_ingredient_foods = sa.Table(
"households_to_ingredient_foods",
SqlAlchemyBase.metadata,
sa.Column("household_id", GUID, sa.ForeignKey("households.id"), index=True),
sa.Column("food_id", GUID, sa.ForeignKey("ingredient_foods.id"), index=True),
sa.UniqueConstraint("household_id", "food_id", name="household_id_food_id_key"),
)


class IngredientUnitModel(SqlAlchemyBase, BaseMixins):
@@ -142,11 +152,13 @@ class IngredientFoodModel(SqlAlchemyBase, BaseMixins):
# ID Relationships
group_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False, index=True)
group: Mapped["Group"] = orm.relationship("Group", back_populates="ingredient_foods", foreign_keys=[group_id])
households: Mapped[list["Household"]] = orm.relationship(
"Household", secondary=households_to_ingredient_foods, back_populates="ingredient_foods"
)

name: Mapped[str | None] = mapped_column(String)
plural_name: Mapped[str | None] = mapped_column(String)
description: Mapped[str | None] = mapped_column(String)
on_hand: Mapped[bool] = mapped_column(Boolean)

ingredients: Mapped[list["RecipeIngredientModel"]] = orm.relationship(
"RecipeIngredientModel", back_populates="food"
@@ -165,6 +177,9 @@ class IngredientFoodModel(SqlAlchemyBase, BaseMixins):
name_normalized: Mapped[str | None] = mapped_column(sa.String, index=True)
plural_name_normalized: Mapped[str | None] = mapped_column(sa.String, index=True)

# Deprecated
on_hand: Mapped[bool] = mapped_column(Boolean)

@api_extras
@auto_init()
def __init__(
17 changes: 16 additions & 1 deletion mealie/db/models/recipe/tool.py
Original file line number Diff line number Diff line change
@@ -10,8 +10,17 @@

if TYPE_CHECKING:
from ..group import Group
from ..household import Household
from . import RecipeModel

households_to_tools = Table(
"households_to_tools",
SqlAlchemyBase.metadata,
Column("household_id", GUID, ForeignKey("households.id"), index=True),
Column("tool_id", GUID, ForeignKey("tools.id"), index=True),
UniqueConstraint("household_id", "tool_id", name="household_id_tool_id_key"),
)

recipes_to_tools = Table(
"recipes_to_tools",
SqlAlchemyBase.metadata,
@@ -40,11 +49,17 @@ class Tool(SqlAlchemyBase, BaseMixins):

name: Mapped[str] = mapped_column(String, index=True, nullable=False)
slug: Mapped[str] = mapped_column(String, index=True, nullable=False)
on_hand: Mapped[bool | None] = mapped_column(Boolean, default=False)

households: Mapped[list["Household"]] = orm.relationship(
"Household", secondary=households_to_tools, back_populates="tools"
)
recipes: Mapped[list["RecipeModel"]] = orm.relationship(
"RecipeModel", secondary=recipes_to_tools, back_populates="tools"
)

# Deprecated
on_hand: Mapped[bool | None] = mapped_column(Boolean, default=False)

@auto_init()
def __init__(self, name, **_) -> None:
self.slug = slugify(name)