- 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>
29 lines
957 B
Python
29 lines
957 B
Python
"""
|
|
SSH 密钥 ORM 模型.
|
|
"""
|
|
from sqlalchemy import String, Integer, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from app.database import Base
|
|
from typing import Optional, List
|
|
|
|
|
|
class SshKey(Base):
|
|
"""
|
|
SSH 密钥模型.
|
|
|
|
存储加密的 SSH 私钥,用于 Git 操作.
|
|
"""
|
|
__tablename__ = "ssh_keys"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
name: Mapped[str] = mapped_column(String(100), nullable=False, unique=True)
|
|
private_key: Mapped[str] = mapped_column(Text, nullable=False)
|
|
fingerprint: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
|
created_at: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
|
|
# 关系
|
|
servers: Mapped[List["Server"]] = relationship("Server", back_populates="ssh_key")
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<SshKey(id={self.id}, name='{self.name}', fingerprint='{self.fingerprint}')>"
|