Coverage for app / models / ping_log.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-05 17:54 +0000

1import uuid 

2from datetime import datetime, timezone 

3 

4from sqlalchemy import ForeignKey, Integer, String, Boolean, DateTime, Text, func, Index 

5from sqlalchemy.orm import Mapped, mapped_column, relationship 

6 

7from app.db.base import Base 

8 

9 

10class PingLog(Base): 

11 __tablename__ = "ping_logs" 

12 

13 __table_args__ = ( 

14 Index("ix_ping_logs_monitor_id_timestamp", "monitor_id", "timestamp"), 

15 ) 

16 

17 id: Mapped[uuid.UUID] = mapped_column(primary_key=True, default=uuid.uuid4) 

18 monitor_id: Mapped[uuid.UUID] = mapped_column(ForeignKey("monitors.id"), nullable=False) 

19 

20 timestamp: Mapped[datetime] = mapped_column( 

21 DateTime(timezone=True), 

22 server_default=func.now(), 

23 default=lambda: datetime.now(timezone.utc), 

24 ) 

25 status_code: Mapped[int | None] = mapped_column(Integer, nullable=True) 

26 response_ms: Mapped[int | None] = mapped_column(Integer, nullable=True) 

27 is_up: Mapped[bool] = mapped_column(Boolean, nullable=False) 

28 error_message: Mapped[str | None] = mapped_column(Text, nullable=True) 

29 

30 monitor: Mapped["Monitor"] = relationship("Monitor", back_populates="ping_logs")