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..2aa966ca --- /dev/null +++ b/alembic/versions/20231213_1307_727cb6912bd5_add_prices_product_name_field.py @@ -0,0 +1,30 @@ +"""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)) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("prices", "product_name") + # ### end Alembic commands ### diff --git a/app/models.py b/app/models.py index e6c16b4e..8d07b450 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) 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..b26bad84 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( + default=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",