- Created SshKey model with encrypted private key storage - Created Server model with Gitea configuration and SshKey relationship - Created Repo model with repository mirror info and Server relationship - Created SyncLog model with sync operation logs and Repo relationship - Updated models/__init__.py to export all models - All models use Integer (Unix timestamp) for datetime fields - Proper bidirectional relationships using back_populates - Added comprehensive test suite for all models and relationships Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
34 lines
1.4 KiB
Python
34 lines
1.4 KiB
Python
"""
|
|
仓库 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"<Repo(id={self.id}, name='{self.name}', full_name='{self.full_name}', status='{self.status}')>"
|