Skip to content

Commit

Permalink
feat: new Product.labels_tags array field (#208)
Browse files Browse the repository at this point in the history
* Add Product.labels_tags field

* Add to schema. Sync with OFF. Update tests
  • Loading branch information
raphodn authored Feb 15, 2024
1 parent ba5b917 commit 95aa5fb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Add Product labels_tags field
Revision ID: 770709475132
Revises: d2d14a95ae1c
Create Date: 2024-02-15 11:49:43.242694
"""
from typing import Sequence, Union

import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "770709475132"
down_revision: Union[str, None] = "d2d14a95ae1c"
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(
"products",
sa.Column(
"labels_tags",
postgresql.ARRAY(sa.String()),
server_default="{}",
nullable=True,
),
)
op.create_index(
op.f("ix_products_labels_tags"), "products", ["labels_tags"], unique=False
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_products_labels_tags"), table_name="products")
op.drop_column("products", "labels_tags")
# ### end Alembic commands ###
1 change: 1 addition & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Product(Base):
categories_tags = Column(ARRAY(String), server_default="{}", index=True)
brands = Column(String)
brands_tags = Column(ARRAY(String), server_default="{}", index=True)
labels_tags = Column(ARRAY(String), server_default="{}", index=True)
image_url = Column(String)
unique_scans_n = Column(Integer, nullable=False, server_default="0")

Expand Down
4 changes: 4 additions & 0 deletions app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class ProductFull(ProductCreate):
description="brands of the product.",
examples=[["douceur-du-verger", "marque-repere"]],
)
labels_tags: list[str] = Field(
description="labels of the product.",
examples=[["en:fair-trade", "en:organic", "en:made-in-france"]],
)
image_url: AnyHttpUrl | None = Field(
description="URL of the product image.",
examples=[
Expand Down
3 changes: 2 additions & 1 deletion app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def init_sentry(sentry_dsn: str | None, integrations: list[Integration] | None =
"product_quantity",
"product_quantity_unit",
"categories_tags",
"brands_tags",
"brands",
"brands_tags",
"labels_tags",
"image_url",
"unique_scans_n",
]
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def override_get_db():
categories_tags=["en:spreads", "en:nuts-and-their-products"],
brands="Clément Faugier",
brands_tags=["clement-faugier"],
labels_tags=[],
source="off",
unique_scans_n=20,
)
Expand All @@ -62,6 +63,7 @@ def override_get_db():
categories_tags=["en:spreads", "en:nuts-and-their-products"],
brands="Clément Faugier",
brands_tags=["clement-faugier"],
labels_tags=[],
source="off",
unique_scans_n=10,
)
Expand All @@ -73,6 +75,7 @@ def override_get_db():
categories_tags=["en:spreads", "en:nuts-and-their-products"],
brands="Ethiquable",
brands_tags=["paysans-d-ici", "ethiquable"],
labels_tags=["en:fair-trade", "en:organic", "en:made-in-france"],
source="off",
unique_scans_n=0,
)
Expand Down

0 comments on commit 95aa5fb

Please sign in to comment.