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>
23 lines
656 B
Python
23 lines
656 B
Python
from typing import TYPE_CHECKING, Optional
|
|
|
|
from sqlmodel import Field, Relationship, SQLModel
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.organization import Organization
|
|
|
|
|
|
class UserBase(SQLModel):
|
|
email: str = Field(unique=True, index=True)
|
|
name: str
|
|
is_active: bool = Field(default=True)
|
|
is_superadmin: bool = Field(default=False)
|
|
|
|
|
|
class User(UserBase, table=True):
|
|
__tablename__ = "users"
|
|
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
hashed_password: str
|
|
organization_id: int = Field(foreign_key="organization.id", ondelete="RESTRICT")
|
|
|
|
organization: "Organization" = Relationship(back_populates="users")
|