vinindkoeb/app/models/route.py
carsten d2abe70333 Define core domain models and add first Alembic migration
Nine SQLModel table models covering the Organization/Route hierarchy
(WineCategory, Organization, User, Route, Participant, PurchaseRound,
WineOffering, Order, OrderLine), with explicit tablenames, FK cascade
behavior, and a CHECK constraint preventing a PurchaseRound from
reaching open/closed status without its opens_at/order_deadline_at/
pickup_at dates set. Also fixes the Alembic script template to import
sqlmodel (needed for autogenerate's AutoString column type).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-27 18:51:04 +02:00

30 lines
1.1 KiB
Python

from typing import TYPE_CHECKING, List, Optional
from sqlmodel import Field, Relationship, SQLModel
if TYPE_CHECKING:
from app.models.organization import Organization
from app.models.participant import Participant
from app.models.purchase_round import PurchaseRound
class RouteBase(SQLModel):
name: str
meeting_info: Optional[str] = Field(default=None)
contact_person: Optional[str] = Field(default=None)
contact_phone: Optional[str] = Field(default=None)
class Route(RouteBase, table=True):
__tablename__ = "route"
id: Optional[int] = Field(default=None, primary_key=True)
organization_id: int = Field(foreign_key="organization.id", ondelete="RESTRICT")
organization: "Organization" = Relationship(back_populates="routes")
participants: List["Participant"] = Relationship(
back_populates="route", sa_relationship_kwargs={"cascade": "all, delete-orphan"}
)
purchase_rounds: List["PurchaseRound"] = Relationship(
back_populates="route", sa_relationship_kwargs={"cascade": "all, delete-orphan"}
)