from datetime import datetime
from sqlalchemy import Column, Integer, String, DateTime, Text
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class TriggerLog(Base):
    """触发日志模型"""
    __tablename__ = "trigger_logs"
    
    id = Column(Integer, primary_key=True, index=True)
    repository_name = Column(String(255), nullable=False, index=True)
    branch_name = Column(String(255), nullable=False, index=True)
    commit_sha = Column(String(64), nullable=False)
    job_name = Column(String(255), nullable=False)
    status = Column(String(50), nullable=False, index=True)  # success, failed, pending
    error_message = Column(Text, nullable=True)
    created_at = Column(DateTime, default=datetime.utcnow, nullable=False, index=True)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
    
    def __repr__(self):
        return f"<TriggerLog(id={self.id}, repository={self.repository_name}, branch={self.branch_name}, status={self.status})>" 