Skip to content

Commit

Permalink
Add Product model
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Nov 21, 2023
1 parent 4a4eca1 commit 0895125
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""Create Product table
Revision ID: aead2a83cfa8
Revises: 1c8431a64d3a
Create Date: 2023-11-21 18:56:39.786743
"""
from typing import Sequence, Union

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "df15f7cacf48"
down_revision: Union[str, None] = "1c8431a64d3a"
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.create_table(
"products",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("code", sa.String(), nullable=True),
sa.Column("off_source", sa.String(length=255), nullable=True),
sa.Column("off_name", sa.String(), nullable=True),
sa.Column("off_quantity", sa.Integer(), nullable=True),
sa.Column("off_image_url", sa.String(), nullable=True),
sa.Column(
"created",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=True,
),
sa.Column("updated", sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f("ix_products_id"), "products", ["id"], unique=False)
op.create_index(op.f("ix_products_off_id"), "products", ["off_id"], unique=True)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_products_off_id"), table_name="products")
op.drop_index(op.f("ix_products_id"), table_name="products")
op.drop_table("products")
# ### end Alembic commands ###
7 changes: 7 additions & 0 deletions app/enums.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from enum import Enum


class ProductOFFSource(Enum):
OFF = "OFF" # Open Food Facts
OPF = "OPF" # Open Products Facts
OPFF = "OPFF" # Open Pet Food Facts
OBF = "OBF" # Open Beauty Facts


class LocationOSMType(Enum):
NODE = "NODE"
WAY = "WAY"
Expand Down
19 changes: 17 additions & 2 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sqlalchemy_utils.types.currency import CurrencyType

from app.db import Base
from app.enums import LocationOSMType
from app.enums import LocationOSMType, ProductOFFSource

force_auto_coercion()

Expand All @@ -31,12 +31,27 @@ class User(Base):
__tablename__ = "users"


class Product(Base):
id = Column(Integer, primary_key=True, index=True)

code = Column(String, unique=True, index=True)

off_source = Column(ChoiceType(ProductOFFSource))
off_name = Column(String)
off_quantity = Column(Integer)
off_image_url = Column(String)

created = Column(DateTime(timezone=True), server_default=func.now())
updated = Column(DateTime(timezone=True), onupdate=func.now())

__tablename__ = "products"


class Location(Base):
id = Column(Integer, primary_key=True, index=True)

osm_id = Column(BigInteger)
osm_type = Column(ChoiceType(LocationOSMType))

osm_name = Column(String)
osm_display_name = Column(String)
osm_address_postcode = Column(String)
Expand Down

0 comments on commit 0895125

Please sign in to comment.