32 lines
959 B
Python
32 lines
959 B
Python
"""Bus schedule model."""
|
|
from sqlmodel import SQLModel, Field, Column
|
|
from datetime import datetime, time
|
|
from typing import Optional
|
|
from enum import Enum
|
|
from uuid import UUID, uuid4
|
|
from sqlalchemy import DateTime, func
|
|
|
|
|
|
class BusScheduleType(str, Enum):
|
|
"""Schedule type enumeration."""
|
|
WEEKDAY = "weekday"
|
|
WEEKEND = "weekend"
|
|
HOLIDAY = "holiday"
|
|
|
|
|
|
class BusSchedule(SQLModel, table=True):
|
|
"""Bus schedule model."""
|
|
|
|
__tablename__ = "bus_schedules"
|
|
|
|
id: Optional[UUID] = Field(default_factory=uuid4, primary_key=True)
|
|
route_id: UUID = Field(foreign_key="routes.id")
|
|
departure_time: time
|
|
frequency_minutes: Optional[int] = 30
|
|
schedule_type: BusScheduleType = BusScheduleType.WEEKDAY
|
|
is_active: bool = Field(default=True)
|
|
is_published: bool = Field(default=False)
|
|
notes: Optional[str] = None
|
|
created_at: Optional[datetime] = Field(sa_column=Column(DateTime, server_default=func.now()))
|
|
|