M34: enforce domain integrity in PostgreSQL
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Boolean, Integer, String
|
||||
from sqlalchemy import Boolean, CheckConstraint, Integer, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.core.db import Base
|
||||
@@ -9,6 +9,16 @@ OPERATIONAL_STATUSES = ("available", "rented", "cleaning", "maintenance", "block
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user