feat: add MarketPlace model, migration, and market_url_for helper

Introduces per-page markets (Phase 2):
- MarketPlace model with soft-delete and unique slug index
- NavTop gains market_id FK to scope nav hierarchy per market
- Migration with backfill creates default 'suma-market' for existing market page
- market_url_for() cross-app URL helper

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-10 18:08:18 +00:00
parent 3cc5730377
commit 7eb66fbf24
6 changed files with 174 additions and 1 deletions

View File

@@ -186,11 +186,18 @@ class NavTop(Base):
id: Mapped[int] = mapped_column(primary_key=True)
label: Mapped[str] = mapped_column(String(255), nullable=False)
slug: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
market_id: Mapped[Optional[int]] = mapped_column(
Integer,
ForeignKey("market_places.id", ondelete="SET NULL"),
nullable=True,
index=True,
)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, server_default=func.now())
deleted_at: Mapped[Optional[datetime]] = mapped_column(DateTime(timezone=True))
listings: Mapped[List["Listing"]] = relationship(back_populates="top", cascade="all, delete-orphan")
market = relationship("MarketPlace", back_populates="nav_tops")
__table_args__ = (UniqueConstraint("label", "slug", name="uq_nav_tops_label_slug"),)