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

Improve Database indexing #2104

Merged
merged 3 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion mealie/db/models/_model_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class SqlAlchemyBase(DeclarativeBase):
id: Mapped[int] = mapped_column(Integer, primary_key=True)
created_at: Mapped[datetime | None] = mapped_column(DateTime, default=datetime.now)
created_at: Mapped[datetime | None] = mapped_column(DateTime, default=datetime.now, index=True)
update_at: Mapped[datetime | None] = mapped_column(DateTime, default=datetime.now, onupdate=datetime.now)


Expand Down
4 changes: 2 additions & 2 deletions mealie/db/models/group/cookbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class CookBook(SqlAlchemyBase, BaseMixins):
id: Mapped[guid.GUID] = mapped_column(guid.GUID, primary_key=True, default=guid.GUID.generate)
position: Mapped[int] = mapped_column(Integer, nullable=False, default=1)

group_id: Mapped[guid.GUID | None] = mapped_column(guid.GUID, ForeignKey("groups.id"))
group_id: Mapped[guid.GUID | None] = mapped_column(guid.GUID, ForeignKey("groups.id"), index=True)
group: Mapped[Optional["Group"]] = orm.relationship("Group", back_populates="cookbooks")

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

Expand Down
2 changes: 1 addition & 1 deletion mealie/db/models/group/invite_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GroupInviteToken(SqlAlchemyBase, BaseMixins):
token: Mapped[str] = mapped_column(String, index=True, nullable=False, unique=True)
uses_left: Mapped[int] = mapped_column(Integer, nullable=False, default=1)

group_id: Mapped[guid.GUID | None] = mapped_column(guid.GUID, ForeignKey("groups.id"))
group_id: Mapped[guid.GUID | None] = mapped_column(guid.GUID, ForeignKey("groups.id"), index=True)
group: Mapped[Optional["Group"]] = orm.relationship("Group", back_populates="invite_tokens")

@auto_init()
Expand Down
2 changes: 1 addition & 1 deletion mealie/db/models/group/mealplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GroupMealPlanRules(BaseMixins, SqlAlchemyBase):
__tablename__ = "group_meal_plan_rules"

id: Mapped[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
group_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False)
group_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False, index=True)

day: Mapped[str] = mapped_column(
String, nullable=False, default="unset"
Expand Down
2 changes: 1 addition & 1 deletion mealie/db/models/group/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ReportEntryModel(SqlAlchemyBase, BaseMixins):
exception: Mapped[str] = mapped_column(String, nullable=True)
timestamp: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.utcnow)

report_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("group_reports.id"), nullable=False)
report_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("group_reports.id"), nullable=False, index=True)
report: Mapped["ReportModel"] = orm.relationship("ReportModel", back_populates="entries")

@auto_init()
Expand Down
4 changes: 2 additions & 2 deletions mealie/db/models/group/shopping_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class ShoppingListItem(SqlAlchemyBase, BaseMixins):

# Id's
id: Mapped[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
shopping_list_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("shopping_lists.id"))
shopping_list_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("shopping_lists.id"), index=True)

# Meta
is_ingredient: Mapped[bool | None] = mapped_column(Boolean, default=True)
position: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
position: Mapped[int] = mapped_column(Integer, nullable=False, default=0, index=True)
checked: Mapped[bool | None] = mapped_column(Boolean, default=False)

quantity: Mapped[float | None] = mapped_column(Float, default=1)
Expand Down
10 changes: 6 additions & 4 deletions mealie/db/models/recipe/api_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,21 @@ def __init__(self, key, value) -> None:
# used specifically for recipe extras
class ApiExtras(ExtrasGeneric, SqlAlchemyBase):
__tablename__ = "api_extras"
recipee_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("recipes.id"))
recipee_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("recipes.id"), index=True)


class IngredientFoodExtras(ExtrasGeneric, SqlAlchemyBase):
__tablename__ = "ingredient_food_extras"
ingredient_food_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("ingredient_foods.id"))
ingredient_food_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("ingredient_foods.id"), index=True)


class ShoppingListExtras(ExtrasGeneric, SqlAlchemyBase):
__tablename__ = "shopping_list_extras"
shopping_list_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("shopping_lists.id"))
shopping_list_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("shopping_lists.id"), index=True)


class ShoppingListItemExtras(ExtrasGeneric, SqlAlchemyBase):
__tablename__ = "shopping_list_item_extras"
shopping_list_item_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("shopping_list_items.id"))
shopping_list_item_id: Mapped[GUID | None] = mapped_column(
GUID, sa.ForeignKey("shopping_list_items.id"), index=True
)
2 changes: 1 addition & 1 deletion mealie/db/models/recipe/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class RecipeAsset(SqlAlchemyBase):
__tablename__ = "recipe_assets"
id: Mapped[int] = mapped_column(sa.Integer, primary_key=True)
recipe_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("recipes.id"))
recipe_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("recipes.id"), index=True)
name: Mapped[str | None] = mapped_column(sa.String)
icon: Mapped[str | None] = mapped_column(sa.String)
file_name: Mapped[str | None] = mapped_column(sa.String)
Expand Down
16 changes: 8 additions & 8 deletions mealie/db/models/recipe/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@
group_to_categories = sa.Table(
"group_to_categories",
SqlAlchemyBase.metadata,
sa.Column("group_id", GUID, sa.ForeignKey("groups.id")),
sa.Column("category_id", GUID, sa.ForeignKey("categories.id")),
sa.Column("group_id", GUID, sa.ForeignKey("groups.id"), index=True),
sa.Column("category_id", GUID, sa.ForeignKey("categories.id"), index=True),
)

plan_rules_to_categories = sa.Table(
"plan_rules_to_categories",
SqlAlchemyBase.metadata,
sa.Column("group_plan_rule_id", GUID, sa.ForeignKey("group_meal_plan_rules.id")),
sa.Column("category_id", GUID, sa.ForeignKey("categories.id")),
sa.Column("group_plan_rule_id", GUID, sa.ForeignKey("group_meal_plan_rules.id"), index=True),
sa.Column("category_id", GUID, sa.ForeignKey("categories.id"), index=True),
)

recipes_to_categories = sa.Table(
"recipes_to_categories",
SqlAlchemyBase.metadata,
sa.Column("recipe_id", GUID, sa.ForeignKey("recipes.id")),
sa.Column("category_id", GUID, sa.ForeignKey("categories.id")),
sa.Column("recipe_id", GUID, sa.ForeignKey("recipes.id"), index=True),
sa.Column("category_id", GUID, sa.ForeignKey("categories.id"), index=True),
)

cookbooks_to_categories = sa.Table(
"cookbooks_to_categories",
SqlAlchemyBase.metadata,
sa.Column("cookbook_id", GUID, sa.ForeignKey("cookbooks.id")),
sa.Column("category_id", GUID, sa.ForeignKey("categories.id")),
sa.Column("cookbook_id", GUID, sa.ForeignKey("cookbooks.id"), index=True),
sa.Column("category_id", GUID, sa.ForeignKey("categories.id"), index=True),
)


Expand Down
4 changes: 2 additions & 2 deletions mealie/db/models/recipe/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class RecipeComment(SqlAlchemyBase, BaseMixins):
text: Mapped[str | None] = mapped_column(String)

# Recipe Link
recipe_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("recipes.id"), nullable=False)
recipe_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("recipes.id"), nullable=False, index=True)
recipe: Mapped["RecipeModel"] = orm.relationship("RecipeModel", back_populates="comments")

# User Link
user_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("users.id"), nullable=False)
user_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("users.id"), nullable=False, index=True)
user: Mapped["User"] = orm.relationship(
"User", back_populates="comments", single_parent=True, foreign_keys=[user_id]
)
Expand Down
12 changes: 6 additions & 6 deletions mealie/db/models/recipe/ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class IngredientUnitModel(SqlAlchemyBase, BaseMixins):
id: Mapped[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)

# ID Relationships
group_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False)
group_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False, index=True)
group: Mapped["Group"] = orm.relationship("Group", back_populates="ingredient_units", foreign_keys=[group_id])

name: Mapped[str | None] = mapped_column(String)
Expand All @@ -39,15 +39,15 @@ class IngredientFoodModel(SqlAlchemyBase, BaseMixins):
id: Mapped[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)

# ID Relationships
group_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False)
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])

name: Mapped[str | None] = mapped_column(String)
description: Mapped[str | None] = mapped_column(String)
ingredients: Mapped[list["RecipeIngredient"]] = orm.relationship("RecipeIngredient", back_populates="food")
extras: Mapped[list[IngredientFoodExtras]] = orm.relationship("IngredientFoodExtras", cascade="all, delete-orphan")

label_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("multi_purpose_labels.id"))
label_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("multi_purpose_labels.id"), index=True)
label: Mapped[MultiPurposeLabel | None] = orm.relationship(MultiPurposeLabel, uselist=False, back_populates="foods")

@api_extras
Expand All @@ -59,17 +59,17 @@ def __init__(self, **_) -> None:
class RecipeIngredient(SqlAlchemyBase, BaseMixins):
__tablename__ = "recipes_ingredients"
id: Mapped[int] = mapped_column(Integer, primary_key=True)
position: Mapped[int | None] = mapped_column(Integer)
position: Mapped[int | None] = mapped_column(Integer, index=True)
recipe_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("recipes.id"))

title: Mapped[str | None] = mapped_column(String) # Section Header - Shows if Present
note: Mapped[str | None] = mapped_column(String) # Force Show Text - Overrides Concat

# Scaling Items
unit_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("ingredient_units.id"))
unit_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("ingredient_units.id"), index=True)
unit: Mapped[IngredientUnitModel | None] = orm.relationship(IngredientUnitModel, uselist=False)

food_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("ingredient_foods.id"))
food_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("ingredient_foods.id"), index=True)
food: Mapped[IngredientFoodModel | None] = orm.relationship(IngredientFoodModel, uselist=False)
quantity: Mapped[float | None] = mapped_column(Float)

Expand Down
8 changes: 4 additions & 4 deletions mealie/db/models/recipe/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class RecipeIngredientRefLink(SqlAlchemyBase, BaseMixins):
__tablename__ = "recipe_ingredient_ref_link"
instruction_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("recipe_instructions.id"))
reference_id: Mapped[GUID | None] = mapped_column(GUID)
instruction_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("recipe_instructions.id"), index=True)
reference_id: Mapped[GUID | None] = mapped_column(GUID, index=True)

@auto_init()
def __init__(self, **_) -> None:
Expand All @@ -19,8 +19,8 @@ def __init__(self, **_) -> None:
class RecipeInstruction(SqlAlchemyBase):
__tablename__ = "recipe_instructions"
id: Mapped[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
recipe_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("recipes.id"))
position: Mapped[int | None] = mapped_column(Integer)
recipe_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("recipes.id"), index=True)
position: Mapped[int | None] = mapped_column(Integer, index=True)
type: Mapped[str | None] = mapped_column(String, default="")
title: Mapped[str | None] = mapped_column(String)
text: Mapped[str | None] = mapped_column(String)
Expand Down
2 changes: 1 addition & 1 deletion mealie/db/models/recipe/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Note(SqlAlchemyBase):
__tablename__ = "notes"
id: Mapped[int] = mapped_column(sa.Integer, primary_key=True)
recipe_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("recipes.id"))
recipe_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("recipes.id"), index=True)
title: Mapped[str | None] = mapped_column(sa.String)
text: Mapped[str | None] = mapped_column(sa.String)

Expand Down
2 changes: 1 addition & 1 deletion mealie/db/models/recipe/nutrition.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Nutrition(SqlAlchemyBase):
__tablename__ = "recipe_nutrition"
id: Mapped[int] = mapped_column(sa.Integer, primary_key=True)
recipe_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("recipes.id"))
recipe_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("recipes.id"), index=True)
calories: Mapped[str | None] = mapped_column(sa.String)
fat_content: Mapped[str | None] = mapped_column(sa.String)
fiber_content: Mapped[str | None] = mapped_column(sa.String)
Expand Down
2 changes: 1 addition & 1 deletion mealie/db/models/recipe/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
)

# General Recipe Properties
name: Mapped[str] = mapped_column(sa.String, nullable=False)
name: Mapped[str] = mapped_column(sa.String, nullable=False, index=True)
description: Mapped[str | None] = mapped_column(sa.String)
image: Mapped[str | None] = mapped_column(sa.String)

Expand Down
6 changes: 3 additions & 3 deletions mealie/db/models/recipe/recipe_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class RecipeTimelineEvent(SqlAlchemyBase, BaseMixins):
id: Mapped[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)

# Parent Recipe
recipe_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("recipes.id"), nullable=False)
recipe_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("recipes.id"), nullable=False, index=True)
recipe: Mapped["RecipeModel"] = relationship("RecipeModel", back_populates="timeline_events")

# Related User (Actor)
user_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("users.id"), nullable=False)
user_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("users.id"), nullable=False, index=True)
user: Mapped["User"] = relationship(
"User", back_populates="recipe_timeline_events", single_parent=True, foreign_keys=[user_id]
)
Expand All @@ -34,7 +34,7 @@ class RecipeTimelineEvent(SqlAlchemyBase, BaseMixins):
image: Mapped[str | None] = mapped_column(String)

# Timestamps
timestamp: Mapped[datetime | None] = mapped_column(DateTime)
timestamp: Mapped[datetime | None] = mapped_column(DateTime, index=True)

@auto_init()
def __init__(
Expand Down
2 changes: 1 addition & 1 deletion mealie/db/models/recipe/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class RecipeSettings(SqlAlchemyBase):
__tablename__ = "recipe_settings"
id: Mapped[int] = mapped_column(sa.Integer, primary_key=True)
recipe_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("recipes.id"))
recipe_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("recipes.id"), index=True)
public: Mapped[bool | None] = mapped_column(sa.Boolean)
show_nutrition: Mapped[bool | None] = mapped_column(sa.Boolean)
show_assets: Mapped[bool | None] = mapped_column(sa.Boolean)
Expand Down
2 changes: 1 addition & 1 deletion mealie/db/models/recipe/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RecipeShareTokenModel(SqlAlchemyBase, BaseMixins):

group_id: Mapped[GUID] = mapped_column(GUID, sa.ForeignKey("groups.id"), nullable=False, index=True)

recipe_id: Mapped[GUID] = mapped_column(GUID, sa.ForeignKey("recipes.id"), nullable=False)
recipe_id: Mapped[GUID] = mapped_column(GUID, sa.ForeignKey("recipes.id"), nullable=False, index=True)
recipe: Mapped["RecipeModel"] = sa.orm.relationship("RecipeModel", back_populates="share_tokens", uselist=False)

expires_at: Mapped[datetime] = mapped_column(sa.DateTime, nullable=False)
Expand Down
12 changes: 6 additions & 6 deletions mealie/db/models/recipe/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
recipes_to_tags = sa.Table(
"recipes_to_tags",
SqlAlchemyBase.metadata,
sa.Column("recipe_id", guid.GUID, sa.ForeignKey("recipes.id")),
sa.Column("tag_id", guid.GUID, sa.ForeignKey("tags.id")),
sa.Column("recipe_id", guid.GUID, sa.ForeignKey("recipes.id"), index=True),
sa.Column("tag_id", guid.GUID, sa.ForeignKey("tags.id"), index=True),
)

plan_rules_to_tags = sa.Table(
"plan_rules_to_tags",
SqlAlchemyBase.metadata,
sa.Column("plan_rule_id", guid.GUID, sa.ForeignKey("group_meal_plan_rules.id")),
sa.Column("tag_id", guid.GUID, sa.ForeignKey("tags.id")),
sa.Column("plan_rule_id", guid.GUID, sa.ForeignKey("group_meal_plan_rules.id"), index=True),
sa.Column("tag_id", guid.GUID, sa.ForeignKey("tags.id"), index=True),
)

cookbooks_to_tags = sa.Table(
"cookbooks_to_tags",
SqlAlchemyBase.metadata,
sa.Column("cookbook_id", guid.GUID, sa.ForeignKey("cookbooks.id")),
sa.Column("tag_id", guid.GUID, sa.ForeignKey("tags.id")),
sa.Column("cookbook_id", guid.GUID, sa.ForeignKey("cookbooks.id"), index=True),
sa.Column("tag_id", guid.GUID, sa.ForeignKey("tags.id"), index=True),
)


Expand Down
10 changes: 5 additions & 5 deletions mealie/db/models/recipe/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
recipes_to_tools = Table(
"recipes_to_tools",
SqlAlchemyBase.metadata,
Column("recipe_id", GUID, ForeignKey("recipes.id")),
Column("tool_id", GUID, ForeignKey("tools.id")),
Column("recipe_id", GUID, ForeignKey("recipes.id"), index=True),
Column("tool_id", GUID, ForeignKey("tools.id"), index=True),
)

cookbooks_to_tools = Table(
"cookbooks_to_tools",
SqlAlchemyBase.metadata,
Column("cookbook_id", GUID, ForeignKey("cookbooks.id")),
Column("tool_id", GUID, ForeignKey("tools.id")),
Column("cookbook_id", GUID, ForeignKey("cookbooks.id"), index=True),
Column("tool_id", GUID, ForeignKey("tools.id"), index=True),
)


Expand All @@ -33,7 +33,7 @@ class Tool(SqlAlchemyBase, BaseMixins):
id: Mapped[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)

# ID Relationships
group_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False)
group_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False, index=True)
group: Mapped["Group"] = orm.relationship("Group", back_populates="tools", foreign_keys=[group_id])

name: Mapped[str] = mapped_column(String, index=True, unique=True, nullable=False)
Expand Down
2 changes: 1 addition & 1 deletion mealie/db/models/users/password_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class PasswordResetModel(SqlAlchemyBase, BaseMixins):
__tablename__ = "password_reset_tokens"

user_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("users.id"), nullable=False)
user_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("users.id"), nullable=False, index=True)
user: Mapped["User"] = orm.relationship("User", back_populates="password_reset_tokens", uselist=False)
token: Mapped[str] = mapped_column(String(64), unique=True, nullable=False)

Expand Down
4 changes: 2 additions & 2 deletions mealie/db/models/users/user_to_favorite.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
users_to_favorites = Table(
"users_to_favorites",
SqlAlchemyBase.metadata,
Column("user_id", GUID, ForeignKey("users.id")),
Column("recipe_id", GUID, ForeignKey("recipes.id")),
Column("user_id", GUID, ForeignKey("users.id"), index=True),
Column("recipe_id", GUID, ForeignKey("recipes.id"), index=True),
)
4 changes: 2 additions & 2 deletions mealie/db/models/users/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
class LongLiveToken(SqlAlchemyBase, BaseMixins):
__tablename__ = "long_live_tokens"
name: Mapped[str] = mapped_column(String, nullable=False)
token: Mapped[str] = mapped_column(String, nullable=False)
token: Mapped[str] = mapped_column(String, nullable=False, index=True)

user_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("users.id"))
user_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("users.id"), index=True)
user: Mapped[Optional["User"]] = orm.relationship("User")

def __init__(self, name, token, user_id, **_) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from mealie.services.backups_v2.alchemy_exporter import AlchemyExporter

ALEMBIC_VERSIONS = [
{"version_num": "165d943c64ee"},
{"version_num": "ff5f73b01a7a"},
]


Expand Down