From d211c0a8b920bc8dc1b9e19c6af0995fed9c15eb Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Mon, 27 Nov 2023 10:10:50 +0100 Subject: [PATCH] feat: add Proof.type field (#68) * Add Proof.type field * Update schema * remove retailer --- ..._1726_cce1da5c6733_add_proof_type_field.py | 30 +++++++++++++++++++ app/enums.py | 6 ++++ app/models.py | 4 ++- app/schemas.py | 3 +- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 alembic/versions/20231125_1726_cce1da5c6733_add_proof_type_field.py diff --git a/alembic/versions/20231125_1726_cce1da5c6733_add_proof_type_field.py b/alembic/versions/20231125_1726_cce1da5c6733_add_proof_type_field.py new file mode 100644 index 00000000..c55251a7 --- /dev/null +++ b/alembic/versions/20231125_1726_cce1da5c6733_add_proof_type_field.py @@ -0,0 +1,30 @@ +"""Add Proof.type field + +Revision ID: cce1da5c6733 +Revises: 012466c0013e +Create Date: 2023-11-25 17:26:49.022693 + +""" +from typing import Sequence, Union + +import sqlalchemy as sa + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "cce1da5c6733" +down_revision: Union[str, None] = "012466c0013e" +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("proofs", sa.Column("type", sa.String(length=255), nullable=True)) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("proofs", "type") + # ### end Alembic commands ### diff --git a/app/enums.py b/app/enums.py index f971a05f..afde645e 100644 --- a/app/enums.py +++ b/app/enums.py @@ -11,3 +11,9 @@ class LocationOSMEnum(Enum): NODE = "NODE" WAY = "WAY" RELATION = "RELATION" + + +class ProofTypeEnum(Enum): + PRICE_TAG = "PRICE_TAG" + RECEIPT = "RECEIPT" + GDPR_REQUEST = "GDPR_REQUEST" diff --git a/app/models.py b/app/models.py index ccda8106..be0def74 100644 --- a/app/models.py +++ b/app/models.py @@ -16,7 +16,7 @@ from sqlalchemy_utils.types.choice import ChoiceType from app.db import Base -from app.enums import CurrencyEnum, LocationOSMEnum +from app.enums import CurrencyEnum, LocationOSMEnum, ProofTypeEnum force_auto_coercion() @@ -77,6 +77,8 @@ class Proof(Base): file_path = Column(String, nullable=False) mimetype = Column(String, index=True) + type = Column(ChoiceType(ProofTypeEnum)) + prices: Mapped[list["Price"]] = relationship(back_populates="proof") owner = Column(String, index=True) diff --git a/app/schemas.py b/app/schemas.py index 7d49bf17..0da29b1a 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -12,7 +12,7 @@ model_validator, ) -from app.enums import CurrencyEnum, LocationOSMEnum +from app.enums import CurrencyEnum, LocationOSMEnum, ProofTypeEnum from app.models import Price @@ -182,6 +182,7 @@ class ProofCreate(BaseModel): file_path: str mimetype: str + type: ProofTypeEnum class ProofBase(ProofCreate):