refactor/recipe-to-snake-case (#364)

* formatting

* snake case all recipes entries

* set foreign key to int

* run scheduler at startup and not import

* set SQLite file path before imports

Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
Hayden
2021-04-28 21:17:49 -08:00
committed by GitHub
parent ee445e7f54
commit 61e0a52100
19 changed files with 107 additions and 104 deletions

View File

@@ -9,7 +9,7 @@ from mealie.db.models.model_base import BaseMixins, SqlAlchemyBase
class Meal(SqlAlchemyBase):
__tablename__ = "meal"
id = sa.Column(sa.Integer, primary_key=True)
parent_id = sa.Column(sa.String, sa.ForeignKey("mealplan.uid"))
parent_id = sa.Column(sa.Integer, sa.ForeignKey("mealplan.uid"))
slug = sa.Column(sa.String)
name = sa.Column(sa.String)
date = sa.Column(sa.Date)

View File

@@ -5,7 +5,7 @@ from mealie.db.models.model_base import SqlAlchemyBase
class ApiExtras(SqlAlchemyBase):
__tablename__ = "api_extras"
id = sa.Column(sa.Integer, primary_key=True)
parent_id = sa.Column(sa.String, sa.ForeignKey("recipes.id"))
parent_id = sa.Column(sa.Integer, sa.ForeignKey("recipes.id"))
key_name = sa.Column(sa.String, unique=True)
value = sa.Column(sa.String)

View File

@@ -5,7 +5,7 @@ from mealie.db.models.model_base import SqlAlchemyBase
class RecipeAsset(SqlAlchemyBase):
__tablename__ = "recipe_assets"
id = sa.Column(sa.Integer, primary_key=True)
parent_id = sa.Column(sa.String, sa.ForeignKey("recipes.id"))
parent_id = sa.Column(sa.Integer, sa.ForeignKey("recipes.id"))
name = sa.Column(sa.String)
icon = sa.Column(sa.String)
file_name = sa.Column(sa.String)

View File

@@ -41,7 +41,7 @@ class Category(SqlAlchemyBase):
id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.String, index=True, nullable=False)
slug = sa.Column(sa.String, index=True, unique=True, nullable=False)
recipes = orm.relationship("RecipeModel", secondary=recipes2categories, back_populates="recipeCategory")
recipes = orm.relationship("RecipeModel", secondary=recipes2categories, back_populates="recipe_category")
@validates("name")
def validate_name(self, key, name):

View File

@@ -6,7 +6,7 @@ class RecipeIngredient(SqlAlchemyBase):
__tablename__ = "recipes_ingredients"
id = sa.Column(sa.Integer, primary_key=True)
position = sa.Column(sa.Integer)
parent_id = sa.Column(sa.String, sa.ForeignKey("recipes.id"))
parent_id = sa.Column(sa.Integer, sa.ForeignKey("recipes.id"))
ingredient = sa.Column(sa.String)
def update(self, ingredient):

View File

@@ -5,7 +5,7 @@ from mealie.db.models.model_base import SqlAlchemyBase
class RecipeInstruction(SqlAlchemyBase):
__tablename__ = "recipe_instructions"
id = sa.Column(sa.Integer, primary_key=True)
parent_id = sa.Column(sa.String, sa.ForeignKey("recipes.id"))
parent_id = sa.Column(sa.Integer, sa.ForeignKey("recipes.id"))
position = sa.Column(sa.Integer)
type = sa.Column(sa.String, default="")
text = sa.Column(sa.String)

View File

@@ -5,7 +5,7 @@ from mealie.db.models.model_base import SqlAlchemyBase
class Note(SqlAlchemyBase):
__tablename__ = "notes"
id = sa.Column(sa.Integer, primary_key=True)
parent_id = sa.Column(sa.String, sa.ForeignKey("recipes.id"))
parent_id = sa.Column(sa.Integer, sa.ForeignKey("recipes.id"))
title = sa.Column(sa.String)
text = sa.Column(sa.String)

View File

@@ -5,29 +5,29 @@ from mealie.db.models.model_base import SqlAlchemyBase
class Nutrition(SqlAlchemyBase):
__tablename__ = "recipe_nutrition"
id = sa.Column(sa.Integer, primary_key=True)
parent_id = sa.Column(sa.String, sa.ForeignKey("recipes.id"))
parent_id = sa.Column(sa.Integer, sa.ForeignKey("recipes.id"))
calories = sa.Column(sa.String)
fatContent = sa.Column(sa.String)
fiberContent = sa.Column(sa.String)
proteinContent = sa.Column(sa.String)
carbohydrateContent = sa.Column(sa.String)
sodiumContent = sa.Column(sa.String)
sugarContent = sa.Column(sa.String)
fat_content = sa.Column(sa.String)
fiber_content = sa.Column(sa.String)
protein_content = sa.Column(sa.String)
carbohydrate_content = sa.Column(sa.String)
sodium_content = sa.Column(sa.String)
sugar_content = sa.Column(sa.String)
def __init__(
self,
calories=None,
fatContent=None,
fiberContent=None,
proteinContent=None,
sodiumContent=None,
sugarContent=None,
carbohydrateContent=None,
fat_content=None,
fiber_content=None,
protein_content=None,
sodium_content=None,
sugar_content=None,
carbohydrate_content=None,
) -> None:
self.calories = calories
self.fatContent = fatContent
self.fiberContent = fiberContent
self.proteinContent = proteinContent
self.sodiumContent = sodiumContent
self.sugarContent = sugarContent
self.carbohydrateContent = carbohydrateContent
self.fat_content = fat_content
self.fiber_content = fiber_content
self.protein_content = protein_content
self.sodium_content = sodium_content
self.sugar_content = sugar_content
self.carbohydrate_content = carbohydrate_content

View File

@@ -27,24 +27,24 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
name = sa.Column(sa.String, nullable=False)
description = sa.Column(sa.String)
image = sa.Column(sa.String)
totalTime = sa.Column(sa.String)
prepTime = sa.Column(sa.String)
performTime = sa.Column(sa.String)
total_time = sa.Column(sa.String)
prep_time = sa.Column(sa.String)
perform_time = sa.Column(sa.String)
cookTime = sa.Column(sa.String)
recipeYield = sa.Column(sa.String)
recipe_yield = sa.Column(sa.String)
recipeCuisine = sa.Column(sa.String)
tools: list[Tool] = orm.relationship("Tool", cascade="all, delete-orphan")
assets: list[RecipeAsset] = orm.relationship("RecipeAsset", cascade="all, delete-orphan")
nutrition: Nutrition = orm.relationship("Nutrition", uselist=False, cascade="all, delete-orphan")
recipeCategory: list = orm.relationship("Category", secondary=recipes2categories, back_populates="recipes")
recipe_category: list = orm.relationship("Category", secondary=recipes2categories, back_populates="recipes")
recipeIngredient: list[RecipeIngredient] = orm.relationship(
recipe_ingredient: list[RecipeIngredient] = orm.relationship(
"RecipeIngredient",
cascade="all, delete-orphan",
order_by="RecipeIngredient.position",
collection_class=ordering_list("position"),
)
recipeInstructions: list[RecipeInstruction] = orm.relationship(
recipe_instructions: list[RecipeInstruction] = orm.relationship(
"RecipeInstruction",
cascade="all, delete-orphan",
order_by="RecipeInstruction.position",
@@ -55,10 +55,10 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
slug = sa.Column(sa.String, index=True, unique=True)
settings = orm.relationship("RecipeSettings", uselist=False, cascade="all, delete-orphan")
tags: list[Tag] = orm.relationship("Tag", secondary=recipes2tags, back_populates="recipes")
dateAdded = sa.Column(sa.Date, default=date.today)
date_added = sa.Column(sa.Date, default=date.today)
notes: list[Note] = orm.relationship("Note", cascade="all, delete-orphan")
rating = sa.Column(sa.Integer)
orgURL = sa.Column(sa.String)
org_url = sa.Column(sa.String)
extras: list[ApiExtras] = orm.relationship("ApiExtras", cascade="all, delete-orphan")
@validates("name")
@@ -72,22 +72,22 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
name: str = None,
description: str = None,
image: str = None,
recipeYield: str = None,
recipeIngredient: list[str] = None,
recipeInstructions: list[dict] = None,
recipe_yield: str = None,
recipe_ingredient: list[str] = None,
recipe_instructions: list[dict] = None,
recipeCuisine: str = None,
totalTime: str = None,
prepTime: str = None,
total_time: str = None,
prep_time: str = None,
nutrition: dict = None,
tools: list[str] = None,
performTime: str = None,
perform_time: str = None,
slug: str = None,
recipeCategory: list[str] = None,
recipe_category: list[str] = None,
tags: list[str] = None,
dateAdded: datetime.date = None,
date_added: datetime.date = None,
notes: list[dict] = None,
rating: int = None,
orgURL: str = None,
org_url: str = None,
extras: dict = None,
assets: list = None,
settings: dict = None,
@@ -103,28 +103,28 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
self.tools = [Tool(tool=x) for x in tools] if tools else []
self.recipeYield = recipeYield
self.recipeIngredient = [RecipeIngredient(ingredient=ingr) for ingr in recipeIngredient]
self.recipe_yield = recipe_yield
self.recipe_ingredient = [RecipeIngredient(ingredient=ingr) for ingr in recipe_ingredient]
self.assets = [RecipeAsset(**a) for a in assets]
self.recipeInstructions = [
self.recipe_instructions = [
RecipeInstruction(text=instruc.get("text"), title=instruc.get("title"), type=instruc.get("@type", None))
for instruc in recipeInstructions
for instruc in recipe_instructions
]
self.totalTime = totalTime
self.prepTime = prepTime
self.performTime = performTime
self.total_time = total_time
self.prep_time = prep_time
self.perform_time = perform_time
self.recipeCategory = [Category.create_if_not_exist(session=session, name=cat) for cat in recipeCategory]
self.recipe_category = [Category.create_if_not_exist(session=session, name=cat) for cat in recipe_category]
# Mealie Specific
self.settings = RecipeSettings(**settings) if settings else RecipeSettings()
print(self.settings)
self.tags = [Tag.create_if_not_exist(session=session, name=tag) for tag in tags]
self.slug = slug
self.dateAdded = dateAdded
self.date_added = date_added
self.notes = [Note(**note) for note in notes]
self.rating = rating
self.orgURL = orgURL
self.org_url = org_url
self.extras = [ApiExtras(key=key, value=value) for key, value in extras.items()]
def update(self, *args, **kwargs):

View File

@@ -5,7 +5,7 @@ from mealie.db.models.model_base import SqlAlchemyBase
class Tool(SqlAlchemyBase):
__tablename__ = "tools"
id = sa.Column(sa.Integer, primary_key=True)
parent_id = sa.Column(sa.String, sa.ForeignKey("recipes.id"))
parent_id = sa.Column(sa.Integer, sa.ForeignKey("recipes.id"))
tool = sa.Column(sa.String)
def __init__(self, tool) -> None: