""" 仓库 ORM 模型. """ from sqlalchemy import String, Integer, ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship from app.database import Base from typing import Optional, List class Repo(Base): """ Git 仓库镜像模型. 存储从 Gitea 服务器同步的仓库信息. """ __tablename__ = "repos" id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) server_id: Mapped[int] = mapped_column(Integer, ForeignKey("servers.id"), nullable=False) name: Mapped[str] = mapped_column(String(200), nullable=False) full_name: Mapped[str] = mapped_column(String(300), nullable=False) clone_url: Mapped[str] = mapped_column(String(500), nullable=False) local_path: Mapped[str] = mapped_column(String(500), nullable=False) last_sync_at: Mapped[Optional[int]] = mapped_column(Integer, nullable=True) status: Mapped[str] = mapped_column(String(20), nullable=False, default="pending") created_at: Mapped[int] = mapped_column(Integer, nullable=False) # 关系 server: Mapped["Server"] = relationship("Server", back_populates="repos") sync_logs: Mapped[List["SyncLog"]] = relationship("SyncLog", back_populates="repo", cascade="all, delete-orphan") def __repr__(self) -> str: return f""