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: add Proof.type field #68

Merged
merged 3 commits into from
Nov 27, 2023
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,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 @@ -181,6 +181,7 @@ class ProofCreate(BaseModel):

file_path: str
mimetype: str
type: ProofTypeEnum


class ProofBase(ProofCreate):
Expand Down
Loading