""" 服务器 ORM 模型. """ from sqlalchemy import String, Integer, Text, Boolean, ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship from app.database import Base from typing import Optional, List class Server(Base): """ Gitea 服务器模型. 存储 Gitea 服务器配置和连接信息. """ __tablename__ = "servers" id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) name: Mapped[str] = mapped_column(String(100), nullable=False, unique=True) url: Mapped[str] = mapped_column(String(500), nullable=False) api_token: Mapped[str] = mapped_column(Text, nullable=False) ssh_key_id: Mapped[int] = mapped_column(Integer, ForeignKey("ssh_keys.id"), nullable=False) sync_enabled: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False) schedule_cron: Mapped[Optional[str]] = mapped_column(String(50), nullable=True) local_path: Mapped[str] = mapped_column(String(500), nullable=False) status: Mapped[str] = mapped_column(String(20), nullable=False, default="untested") created_at: Mapped[int] = mapped_column(Integer, nullable=False) updated_at: Mapped[int] = mapped_column(Integer, nullable=False) # 关系 ssh_key: Mapped["SshKey"] = relationship("SshKey", back_populates="servers") repos: Mapped[List["Repo"]] = relationship("Repo", back_populates="server", cascade="all, delete-orphan") def __repr__(self) -> str: return f""