feat: implement all 4 ORM models (SshKey, Server, Repo, SyncLog)
- 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>
This commit is contained in:
31
backend/app/models/sync_log.py
Normal file
31
backend/app/models/sync_log.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
同步日志 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"<SyncLog(id={self.id}, repo_id={self.repo_id}, status='{self.status}', commits_count={self.commits_count})>"
|
||||
Reference in New Issue
Block a user