From d41c6541cc01944eeb902ce55eab03bfbea2e120 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Wed, 13 Dec 2023 13:09:10 +0100 Subject: [PATCH 1/2] Add price.product_name field --- ...cb6912bd5_add_prices_product_name_field.py | 34 +++++++++++++++++++ app/models.py | 1 + app/schemas.py | 7 ++++ tests/test_api.py | 1 + 4 files changed, 43 insertions(+) create mode 100644 alembic/versions/20231213_1307_727cb6912bd5_add_prices_product_name_field.py diff --git a/alembic/versions/20231213_1307_727cb6912bd5_add_prices_product_name_field.py b/alembic/versions/20231213_1307_727cb6912bd5_add_prices_product_name_field.py new file mode 100644 index 00000000..d4a9dbe1 --- /dev/null +++ b/alembic/versions/20231213_1307_727cb6912bd5_add_prices_product_name_field.py @@ -0,0 +1,34 @@ +"""Add prices product_name field + +Revision ID: 727cb6912bd5 +Revises: cce1da5c6733 +Create Date: 2023-12-13 13:07:56.309158 + +""" +from typing import Sequence, Union + +import sqlalchemy as sa + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "727cb6912bd5" +down_revision: Union[str, None] = "cce1da5c6733" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column("prices", sa.Column("product_name", sa.String(), nullable=True)) + op.create_index( + op.f("ix_prices_product_name"), "prices", ["product_name"], unique=False + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f("ix_prices_product_name"), table_name="prices") + op.drop_column("prices", "product_name") + # ### end Alembic commands ### diff --git a/app/models.py b/app/models.py index e6c16b4e..61c9703f 100644 --- a/app/models.py +++ b/app/models.py @@ -94,6 +94,7 @@ class Price(Base): id = Column(Integer, primary_key=True, index=True) product_code = Column(String, nullable=True, index=True) + product_name = Column(String, nullable=True, index=True) category_tag = Column(String, nullable=True, index=True) labels_tags = Column(JSONVariant, nullable=True, index=True) product_id: Mapped[int] = mapped_column(ForeignKey("products.id"), nullable=True) diff --git a/app/schemas.py b/app/schemas.py index 0da29b1a..9f18e8de 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -81,6 +81,7 @@ class LocationBase(LocationCreate): class PriceCreate(BaseModel): model_config = ConfigDict(from_attributes=True, arbitrary_types_allowed=True) + product_code: str | None = Field( default=None, min_length=1, @@ -88,6 +89,12 @@ class PriceCreate(BaseModel): description="barcode (EAN) of the product, as a string.", examples=["16584958", "8001505005707"], ) + product_name: str | None = Field( + defaul=None, + min_length=1, + description="name of the product, as displayed on the receipt or the price tag.", + examples=["PATE NOCCIOLATA BIO 700G"], + ) category_tag: str | None = Field( default=None, min_length=3, diff --git a/tests/test_api.py b/tests/test_api.py index 8537f976..a0ad66df 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -44,6 +44,7 @@ def override_get_db(): LOCATION = LocationCreate(osm_id=3344841823, osm_type="NODE") PRICE_1 = PriceCreate( product_code="8001505005707", + product_name="PATE NOCCIOLATA BIO 700G", # category="en:tomatoes", price=3.5, currency="EUR", From 4b6f20956806fe34f2ff4b52aea0849c93ab1510 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Thu, 14 Dec 2023 13:27:26 +0100 Subject: [PATCH 2/2] Remove index. Fix typo --- ...0231213_1307_727cb6912bd5_add_prices_product_name_field.py | 4 ---- app/models.py | 2 +- app/schemas.py | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/alembic/versions/20231213_1307_727cb6912bd5_add_prices_product_name_field.py b/alembic/versions/20231213_1307_727cb6912bd5_add_prices_product_name_field.py index d4a9dbe1..2aa966ca 100644 --- a/alembic/versions/20231213_1307_727cb6912bd5_add_prices_product_name_field.py +++ b/alembic/versions/20231213_1307_727cb6912bd5_add_prices_product_name_field.py @@ -21,14 +21,10 @@ def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.add_column("prices", sa.Column("product_name", sa.String(), nullable=True)) - op.create_index( - op.f("ix_prices_product_name"), "prices", ["product_name"], unique=False - ) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f("ix_prices_product_name"), table_name="prices") op.drop_column("prices", "product_name") # ### end Alembic commands ### diff --git a/app/models.py b/app/models.py index 61c9703f..8d07b450 100644 --- a/app/models.py +++ b/app/models.py @@ -94,7 +94,7 @@ class Price(Base): id = Column(Integer, primary_key=True, index=True) product_code = Column(String, nullable=True, index=True) - product_name = Column(String, nullable=True, index=True) + product_name = Column(String, nullable=True) category_tag = Column(String, nullable=True, index=True) labels_tags = Column(JSONVariant, nullable=True, index=True) product_id: Mapped[int] = mapped_column(ForeignKey("products.id"), nullable=True) diff --git a/app/schemas.py b/app/schemas.py index 9f18e8de..b26bad84 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -90,7 +90,7 @@ class PriceCreate(BaseModel): examples=["16584958", "8001505005707"], ) product_name: str | None = Field( - defaul=None, + default=None, min_length=1, description="name of the product, as displayed on the receipt or the price tag.", examples=["PATE NOCCIOLATA BIO 700G"],