This commit is contained in:
2025-12-18 21:13:49 +03:00
parent 84b934036b
commit 030af7ca83
45 changed files with 3106 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
from datetime import datetime
from sqlalchemy import DateTime, String, ForeignKey, Index
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.database import Base
class Event(Base):
__tablename__ = "events"
id: Mapped[int] = mapped_column(primary_key=True)
vehicle_id: Mapped[int] = mapped_column(ForeignKey("vehicles.id", ondelete="CASCADE"))
timestamp: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.utcnow)
type: Mapped[str] = mapped_column(String(50), nullable=False) # LONG_STOP, OVERSPEED, CONNECTION_LOST
payload: Mapped[dict] = mapped_column(JSONB, default=dict)
# Relationships
vehicle: Mapped["Vehicle"] = relationship(back_populates="events")
__table_args__ = (
Index("idx_events_vehicle_ts", "vehicle_id", "timestamp"),
Index("idx_events_type", "type"),
)