Introduces PointOfInterest (per-user named locations with lat/lng) and POIDistance (travel time/distance per listing+POI+mode triple) SQLModel entities, plus an Alembic migration to create both tables with indexes and a composite unique constraint.
23 lines
860 B
Python
23 lines
860 B
Python
from datetime import datetime
|
|
|
|
from sqlmodel import SQLModel, Field, UniqueConstraint
|
|
|
|
from models.listing import ListingType
|
|
|
|
|
|
class POIDistance(SQLModel, table=True):
|
|
__table_args__ = (
|
|
UniqueConstraint(
|
|
"listing_id", "listing_type", "poi_id", "travel_mode",
|
|
name="uq_poi_distance_listing_poi_mode",
|
|
),
|
|
)
|
|
|
|
id: int | None = Field(default=None, primary_key=True)
|
|
listing_id: int = Field(index=True, nullable=False)
|
|
listing_type: ListingType = Field(index=True, nullable=False)
|
|
poi_id: int = Field(foreign_key="pointofinterest.id", index=True, nullable=False)
|
|
travel_mode: str = Field(nullable=False) # WALK, BICYCLE, TRANSIT
|
|
duration_seconds: int = Field(nullable=False)
|
|
distance_meters: int = Field(nullable=False)
|
|
computed_at: datetime = Field(default_factory=datetime.utcnow)
|