diff --git a/alembic/versions/20231116_1432_b3b951e016d0_create_location_table.py b/alembic/versions/20231116_1432_b3b951e016d0_create_location_table.py new file mode 100644 index 00000000..e53e7afa --- /dev/null +++ b/alembic/versions/20231116_1432_b3b951e016d0_create_location_table.py @@ -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 ### diff --git a/app/models.py b/app/models.py index 6400d2e6..b26250cb 100644 --- a/app/models.py +++ b/app/models.py @@ -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)) @@ -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"