Skip to content

Commit

Permalink
feat: add Proof.type field (#68)
Browse files Browse the repository at this point in the history
* Add Proof.type field

* Update schema

* remove retailer
  • Loading branch information
raphodn committed Nov 27, 2023
1 parent 5f23977 commit d211c0a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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 ###
6 changes: 6 additions & 0 deletions app/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 3 additions & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
model_validator,
)

from app.enums import CurrencyEnum, LocationOSMEnum
from app.enums import CurrencyEnum, LocationOSMEnum, ProofTypeEnum
from app.models import Price


Expand Down Expand Up @@ -182,6 +182,7 @@ class ProofCreate(BaseModel):

file_path: str
mimetype: str
type: ProofTypeEnum


class ProofBase(ProofCreate):
Expand Down

0 comments on commit d211c0a

Please sign in to comment.