Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new Product.brands_tags array field #207

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Add Product brands_tags field

Revision ID: d2d14a95ae1c
Revises: 76d67467ff32
Create Date: 2024-02-15 11:24:20.984844

"""
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 = "d2d14a95ae1c"
down_revision: Union[str, None] = "76d67467ff32"
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(
"brands_tags",
postgresql.ARRAY(sa.String()),
server_default="{}",
nullable=True,
),
)
op.create_index(
op.f("ix_products_brands_tags"), "products", ["brands_tags"], unique=False
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_products_brands_tags"), table_name="products")
op.drop_column("products", "brands_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 @@ -58,6 +58,7 @@ class Product(Base):
product_quantity_unit = Column(String)
categories_tags = Column(ARRAY(String), server_default="{}", index=True)
brands = Column(String)
brands_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 @@ -79,6 +79,10 @@ class ProductFull(ProductCreate):
description="brand(s) of the product.",
examples=["Rigoni di Asiago", "Lindt"],
)
brands_tags: list[str] = Field(
description="brands of the product.",
examples=[["douceur-du-verger", "marque-repere"]],
)
image_url: AnyHttpUrl | None = Field(
description="URL of the product image.",
examples=[
Expand Down
1 change: 1 addition & 0 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def init_sentry(sentry_dsn: str | None, integrations: list[Integration] | None =
"product_quantity",
"product_quantity_unit",
"categories_tags",
"brands_tags",
"brands",
"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 @@ -50,6 +50,7 @@ def override_get_db():
product_quantity_unit="g",
categories_tags=["en:spreads", "en:nuts-and-their-products"],
brands="Clément Faugier",
brands_tags=["clement-faugier"],
source="off",
unique_scans_n=20,
)
Expand All @@ -60,6 +61,7 @@ def override_get_db():
product_quantity_unit="g",
categories_tags=["en:spreads", "en:nuts-and-their-products"],
brands="Clément Faugier",
brands_tags=["clement-faugier"],
source="off",
unique_scans_n=10,
)
Expand All @@ -70,6 +72,7 @@ def override_get_db():
product_quantity_unit="g",
categories_tags=["en:spreads", "en:nuts-and-their-products"],
brands="Ethiquable",
brands_tags=["paysans-d-ici", "ethiquable"],
source="off",
unique_scans_n=0,
)
Expand Down
Loading