mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-28 13:05:26 -05:00
feat: improve database indexing (#2104)
* add indices to all foreign keys and some fields that are used for ordering and filtering * add missing migrations * update migration orders --------- Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com>
This commit is contained in:
@@ -6,7 +6,7 @@ from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -40,19 +40,21 @@ class ExtrasGeneric:
|
||||
# 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
|
||||
)
|
||||
|
||||
@@ -8,7 +8,7 @@ from mealie.db.models._model_utils.guid import GUID
|
||||
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)
|
||||
|
||||
@@ -19,29 +19,29 @@ logger = root_logger.get_logger()
|
||||
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),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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]
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
@@ -39,7 +39,7 @@ 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)
|
||||
@@ -47,7 +47,7 @@ class IngredientFoodModel(SqlAlchemyBase, BaseMixins):
|
||||
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
|
||||
@@ -59,17 +59,17 @@ class IngredientFoodModel(SqlAlchemyBase, BaseMixins):
|
||||
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)
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ from .._model_utils.guid import GUID
|
||||
|
||||
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:
|
||||
@@ -19,8 +19,8 @@ class RecipeIngredientRefLink(SqlAlchemyBase, BaseMixins):
|
||||
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)
|
||||
|
||||
@@ -8,7 +8,7 @@ from mealie.db.models._model_utils.guid import GUID
|
||||
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)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from mealie.db.models._model_utils.guid import GUID
|
||||
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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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]
|
||||
)
|
||||
@@ -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__(
|
||||
|
||||
@@ -8,7 +8,7 @@ from mealie.db.models._model_utils.guid import GUID
|
||||
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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -19,22 +19,22 @@ logger = root_logger.get_logger()
|
||||
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),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -15,15 +15,15 @@ if TYPE_CHECKING:
|
||||
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),
|
||||
)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -13,7 +13,7 @@ if TYPE_CHECKING:
|
||||
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)
|
||||
|
||||
|
||||
@@ -6,6 +6,6 @@ from .._model_utils import GUID
|
||||
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),
|
||||
)
|
||||
|
||||
@@ -21,9 +21,9 @@ if TYPE_CHECKING:
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user