File size: 1,047 Bytes
32ddb29
 
bf34e9d
32ddb29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bf34e9d
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from datetime import datetime

from sqlalchemy import Boolean, DateTime, Index, Integer, String, func
from sqlalchemy.orm import Mapped, mapped_column

from app.database import Base


class SourceHealth(Base):
    __tablename__ = "source_health"

    id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
    source_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="资源站ID")
    check_type: Mapped[str] = mapped_column(String(20), nullable=False, comment="api/play")
    is_success: Mapped[bool] = mapped_column(Boolean, nullable=False, comment="是否成功")
    response_time_ms: Mapped[int | None] = mapped_column(Integer, comment="响应时间(ms)")
    error_message: Mapped[str | None] = mapped_column(String, comment="错误信息")
    checked_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())

    __table_args__ = (
        # 查询最新健康记录:source_id + checked_at 倒序
        Index("ix_source_health_source_checked", "source_id", "checked_at"),
    )