Skip to content

Commit

Permalink
Add Location model
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Nov 16, 2023
1 parent e43726d commit 0a2cb4b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Create Location table
Revision ID: b3b951e016d0
Revises: 20145023aad0
Create Date: 2023-11-16 14:32:39.734937
"""
from typing import Sequence, Union

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "b3b951e016d0"
down_revision: Union[str, None] = "20145023aad0"
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(
"locations",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("osm_id", sa.BigInteger(), nullable=True),
sa.Column("osm_type", sa.String(length=255), nullable=True),
sa.Column("osm_display_name", sa.String(), nullable=True),
sa.Column("osm_lat", sa.Numeric(precision=11, scale=7), nullable=True),
sa.Column("osm_lon", sa.Numeric(precision=11, scale=7), 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_locations_id"), "locations", ["id"], unique=False)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_locations_id"), table_name="locations")
op.drop_table("locations")
# ### end Alembic commands ###
29 changes: 26 additions & 3 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,38 @@ class User(Base):

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

file_path = Column(String, nullable=False)
mimetype = Column(String, index=True)

prices: Mapped[list["Price"]] = relationship(back_populates="proof")

owner = Column(String, index=True)

created = Column(DateTime(timezone=True), server_default=func.now(), index=True)
prices: Mapped[list["Price"]] = relationship(back_populates="proof")

__tablename__ = "proofs"


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

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

osm_display_name = Column(String)
osm_lat = Column(Numeric(precision=11, scale=7))
osm_lon = Column(Numeric(precision=11, scale=7))

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

__tablename__ = "locations"


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

product_code = Column(String, index=True)

price = Column(Numeric(precision=10, scale=2))
Expand All @@ -53,10 +74,12 @@ class Price(Base):
location_osm_type = Column(ChoiceType(PriceLocationOSMType))

date = Column(Date)
owner = Column(String)

created = Column(DateTime(timezone=True), server_default=func.now())
proof_id: Mapped[int] = mapped_column(ForeignKey("proofs.id"), nullable=True)
proof: Mapped[Proof] = relationship(back_populates="prices")

owner = Column(String)

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

__tablename__ = "prices"

0 comments on commit 0a2cb4b

Please sign in to comment.