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>
20 lines
560 B
Python
20 lines
560 B
Python
from typing import TYPE_CHECKING, List, Optional
|
|
|
|
from sqlmodel import Field, Relationship, SQLModel
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.route import Route
|
|
from app.models.user import User
|
|
|
|
|
|
class OrganizationBase(SQLModel):
|
|
name: str = Field(unique=True)
|
|
|
|
|
|
class Organization(OrganizationBase, table=True):
|
|
__tablename__ = "organization"
|
|
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
|
|
users: List["User"] = Relationship(back_populates="organization")
|
|
routes: List["Route"] = Relationship(back_populates="organization")
|