""" 同步日志 ORM 模型. """ from sqlalchemy import String, Integer, Text, ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship from app.database import Base from typing import Optional, List class SyncLog(Base): """ 同步日志模型. 记录仓库同步操作的详细信息. """ __tablename__ = "sync_logs" id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) repo_id: Mapped[int] = mapped_column(Integer, ForeignKey("repos.id"), nullable=False) status: Mapped[str] = mapped_column(String(20), nullable=False) started_at: Mapped[int] = mapped_column(Integer, nullable=False) finished_at: Mapped[int] = mapped_column(Integer, nullable=False) commits_count: Mapped[Optional[int]] = mapped_column(Integer, nullable=True) error_msg: Mapped[Optional[str]] = mapped_column(Text, nullable=True) created_at: Mapped[int] = mapped_column(Integer, nullable=False) # 关系 repo: Mapped["Repo"] = relationship("Repo", back_populates="sync_logs") def __repr__(self) -> str: return f""