guideCity/backend/app/models/place_content.py
vrubelroman d2ab424e7e Add FastAPI backend with PostGIS-backed nearby search
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>
2026-07-09 18:31:29 +00:00

23 lines
1 KiB
Python

from sqlalchemy import Enum, ForeignKey, String, Text, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.db.base import Base
from app.models.enums import ContentLanguage, ContentLength
class PlaceContent(Base):
__tablename__ = "place_content"
__table_args__ = (UniqueConstraint("place_id", "language", "length", name="uq_place_content_variant"),)
id: Mapped[int] = mapped_column(primary_key=True)
place_id: Mapped[int] = mapped_column(ForeignKey("places.id", ondelete="CASCADE"), nullable=False)
language: Mapped[ContentLanguage] = mapped_column(
Enum(ContentLanguage, name="content_language", native_enum=True), nullable=False
)
length: Mapped[ContentLength] = mapped_column(
Enum(ContentLength, name="content_length", native_enum=True), nullable=False
)
title: Mapped[str] = mapped_column(String(256), nullable=False)
body: Mapped[str] = mapped_column(Text, nullable=False)
place: Mapped["Place"] = relationship(back_populates="contents")