FastAPI service backed by PostgreSQL+PostGIS: cities/places/place_content schema (normalized per-language, per-length content for easy future re-ingestion), Alembic migration, an iterative-radius-expansion nearby search endpoint, a name-search fallback for denied-location flows, and a YAML seed loader CLI. Verified end-to-end against a live Docker Postgres+PostGIS instance (migration, city seed, place/content CRUD, and nearby radius expansion all confirmed working via curl). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
23 lines
946 B
Python
23 lines
946 B
Python
from datetime import datetime
|
|
|
|
from geoalchemy2 import Geography
|
|
from sqlalchemy import DateTime, String, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class City(Base):
|
|
__tablename__ = "cities"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
slug: Mapped[str] = mapped_column(String(64), unique=True, nullable=False)
|
|
name_ru: Mapped[str] = mapped_column(String(128), nullable=False)
|
|
name_en: Mapped[str] = mapped_column(String(128), nullable=False)
|
|
country_code: Mapped[str] = mapped_column(String(2), nullable=False, default="RU")
|
|
center_point = mapped_column(
|
|
Geography(geometry_type="POINT", srid=4326, spatial_index=False), nullable=True
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
places: Mapped[list["Place"]] = relationship(back_populates="city", cascade="all, delete-orphan")
|