Fundamental_Analysis/backend/app/models/progress_tracking.py

39 lines
1.5 KiB
Python

"""
进度追踪数据模型
"""
from sqlalchemy import Column, String, Integer, DateTime, Text, ForeignKey, Index
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
import uuid
from ..core.database import Base
class ProgressTracking(Base):
"""进度追踪表模型"""
__tablename__ = "progress_tracking"
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
report_id = Column(UUID(as_uuid=True), ForeignKey("reports.id", ondelete="CASCADE"), nullable=False)
step_name = Column(String(100), nullable=False, comment="步骤名称")
step_order = Column(Integer, nullable=False, comment="步骤顺序")
status = Column(String(20), nullable=False, default="pending", comment="步骤状态")
started_at = Column(DateTime(timezone=True), comment="开始时间")
completed_at = Column(DateTime(timezone=True), comment="完成时间")
duration_ms = Column(Integer, comment="耗时(毫秒)")
error_message = Column(Text, comment="错误信息")
# 关系
report = relationship("Report", back_populates="progress_tracking")
# 索引
__table_args__ = (
Index('idx_progress_tracking_report_id', 'report_id'),
Index('idx_progress_tracking_status', 'status'),
Index('idx_progress_tracking_order', 'step_order'),
)
def __repr__(self):
return f"<ProgressTracking(id={self.id}, step={self.step_name}, status={self.status})>"