34 lines
1.7 KiB
Python
34 lines
1.7 KiB
Python
from sqlalchemy import Boolean, CheckConstraint, Integer, String
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.core.db import Base
|
|
from app.models.mixins import TimestampMixin, UUIDPrimaryKeyMixin
|
|
|
|
OPERATIONAL_STATUSES = ("available", "rented", "cleaning", "maintenance", "blocked")
|
|
|
|
|
|
class Vehicle(UUIDPrimaryKeyMixin, TimestampMixin, Base):
|
|
__tablename__ = "vehicles"
|
|
__table_args__ = (
|
|
CheckConstraint(
|
|
"operational_status IN ('available','rented','cleaning','maintenance','blocked')",
|
|
name="ck_vehicles_operational_status",
|
|
),
|
|
CheckConstraint("model_year BETWEEN 1900 AND 2100", name="ck_vehicles_model_year"),
|
|
CheckConstraint("odometer_km >= 0", name="ck_vehicles_odometer"),
|
|
CheckConstraint("next_service_km >= 0", name="ck_vehicles_next_service"),
|
|
CheckConstraint("version >= 1", name="ck_vehicles_version"),
|
|
)
|
|
|
|
public_ref: Mapped[str] = mapped_column(String(20), unique=True, nullable=False)
|
|
make: Mapped[str] = mapped_column(String(80), nullable=False)
|
|
model: Mapped[str] = mapped_column(String(80), nullable=False)
|
|
model_year: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
registration_number: Mapped[str] = mapped_column(String(40), unique=True, nullable=False)
|
|
location: Mapped[str] = mapped_column(String(120), nullable=False)
|
|
operational_status: Mapped[str] = mapped_column(String(20), nullable=False)
|
|
odometer_km: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
next_service_km: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|
|
version: Mapped[int] = mapped_column(Integer, nullable=False, default=1)
|