Fix/incorrect quantity column (#1093)

* change database type

* database migration for changing type on PostgreSQL

* update revision

* add exclusion directory

* update recipe-scrapers
This commit is contained in:
Hayden 2022-03-27 09:18:34 -08:00 committed by GitHub
parent 7895dfba70
commit b57e42a3b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 13 deletions

View file

@ -0,0 +1,51 @@
"""convert quantity from integer to float
Revision ID: 263dd6707191
Revises: 6b0f5f32d602
Create Date: 2022-03-23 17:43:34.727829
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "263dd6707191"
down_revision = "6b0f5f32d602"
branch_labels = None
depends_on = None
def is_postgres():
return op.get_context().dialect.name == "postgresql"
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
# SQLite doesn't require migration as types are not inforced.
# Postgres Specifc Migration
if is_postgres():
op.alter_column(
"recipes_ingredients",
"quantity",
type_=sa.Float(),
existing_type=sa.Integer(),
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
# SQLite doesn't require migration as types are not inforced.
# Postgres Specifc Migration
if is_postgres():
op.alter_column(
"recipes_ingredients",
"quantity",
type_=sa.Integer(),
existing_type=sa.Float(),
)
# ### end Alembic commands ###

View file

@ -1,4 +1,4 @@
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, orm
from sqlalchemy import Boolean, Column, Float, ForeignKey, Integer, String, orm
from mealie.db.models._model_base import BaseMixins, SqlAlchemyBase
from mealie.db.models.labels import MultiPurposeLabel
@ -61,7 +61,7 @@ class RecipeIngredient(SqlAlchemyBase, BaseMixins):
food_id = Column(GUID, ForeignKey("ingredient_foods.id"))
food = orm.relationship(IngredientFoodModel, uselist=False)
quantity = Column(Integer)
quantity = Column(Float)
reference_id = Column(GUID) # Reference Links

View file

@ -30,7 +30,7 @@ class BackupV2(BaseService):
# sourcery skip: merge-nested-ifs, reintroduce-else, remove-redundant-continue
exclude = {"mealie.db", "mealie.log", ".secret"}
exclude_ext = {".zip"}
exclude_dirs = {"backups"}
exclude_dirs = {"backups", ".temp"}
timestamp = datetime.datetime.now().strftime("%Y.%m.%d.%H.%M.%S")

8
poetry.lock generated
View file

@ -1229,7 +1229,7 @@ rdflib = ">=5.0.0"
[[package]]
name = "recipe-scrapers"
version = "13.18.1"
version = "13.23.0"
description = "Python package, scraping recipes from all over the internet"
category = "main"
optional = false
@ -1599,7 +1599,7 @@ pgsql = ["psycopg2-binary"]
[metadata]
lock-version = "1.1"
python-versions = "^3.10"
content-hash = "84c1d9352c058da5cc0f50ca195cbe0897ce64abfbe01d08b9da317b6dd70a70"
content-hash = "7541b47452a32f483ab233daa846f07707a3d9da6f4e50c1285249639b1c40fd"
[metadata.files]
aiofiles = [
@ -2527,8 +2527,8 @@ rdflib-jsonld = [
{file = "rdflib_jsonld-0.6.2-py2.py3-none-any.whl", hash = "sha256:011afe67672353ca9978ab9a4bee964dff91f14042f2d8a28c22a573779d2f8b"},
]
recipe-scrapers = [
{file = "recipe_scrapers-13.18.1-py3-none-any.whl", hash = "sha256:0923a413e36d66a7489ef414c36c5d1633bc69c2c860535ae7a0ed6d7d52743d"},
{file = "recipe_scrapers-13.18.1.tar.gz", hash = "sha256:2172ebbba155332c1d26a94242d7f18c82313ec8aa74512d25b3678f138b8576"},
{file = "recipe_scrapers-13.23.0-py3-none-any.whl", hash = "sha256:120b356ca422e4f2afb8c944ecf2b53d3c9c73ac9f5345cf35bc168147056e17"},
{file = "recipe_scrapers-13.23.0.tar.gz", hash = "sha256:d99fbdaa1323e6d11e1378bfda0adc5536bd6acf3c71dc57380898300c577f45"},
]
requests = [
{file = "requests-2.27.1-py2.py3-none-any.whl", hash = "sha256:f22fa1e554c9ddfd16e6e41ac79759e17be9e492b3587efa038054674760e72d"},

View file

@ -31,7 +31,7 @@ passlib = "^1.7.4"
lxml = "^4.7.1"
Pillow = "^8.2.0"
apprise = "^0.9.6"
recipe-scrapers = "^13.18.1"
recipe-scrapers = "^13.23.0"
psycopg2-binary = {version = "^2.9.1", optional = true}
gunicorn = "^20.1.0"
emails = "^0.6"

View file

@ -3,22 +3,26 @@ import json
from mealie.core.config import get_app_settings
from mealie.services.backups_v2.alchemy_exporter import AlchemyExporter
ALEMBIC_VERSIONS = [
{"version_num": "263dd6707191"},
]
def test_alchemy_exporter():
settings = get_app_settings()
exporter = AlchemyExporter(settings.DB_URL)
data = exporter.dump()
assert data["alembic_version"] == [{"version_num": "6b0f5f32d602"}]
assert data["alembic_version"] == ALEMBIC_VERSIONS
assert json.dumps(data, indent=4) # Make sure data is json-serializable
def test_validate_schemas():
schema = {
"alembic_version": [{"version_num": "6b0f5f32d602"}],
"alembic_version": ALEMBIC_VERSIONS,
}
match = {
"alembic_version": [{"version_num": "6b0f5f32d602"}],
"alembic_version": ALEMBIC_VERSIONS,
}
invalid_version = {
@ -29,7 +33,7 @@ def test_validate_schemas():
assert not AlchemyExporter.validate_schemas(schema, invalid_version)
schema_with_tables = {
"alembic_version": [{"version_num": "6b0f5f32d602"}],
"alembic_version": ALEMBIC_VERSIONS,
"recipes": [
{
"id": 1,
@ -37,7 +41,7 @@ def test_validate_schemas():
],
}
match_with_tables = {
"alembic_version": [{"version_num": "6b0f5f32d602"}],
"alembic_version": ALEMBIC_VERSIONS,
"recipes": [
{
"id": 2,