from datetime import datetime from sqlalchemy import DateTime, Integer, String, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column from app.core.database import Base from app.core.utils.time import utc_now class SystemHeartbeat(Base): __tablename__ = "system_heartbeats" __table_args__ = ( UniqueConstraint("component", "instance_id", name="uq_system_heartbeat_component_instance"), ) id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) component: Mapped[str] = mapped_column(String(128), index=True) instance_id: Mapped[str] = mapped_column(String(128), index=True) status: Mapped[str] = mapped_column(String(32), index=True) last_seen_at: Mapped[datetime] = mapped_column(DateTime, default=utc_now, index=True) created_at: Mapped[datetime] = mapped_column(DateTime, default=utc_now, index=True) updated_at: Mapped[datetime] = mapped_column( DateTime, default=utc_now, onupdate=utc_now, )