"""Pre-mortem + Red Team 模型。""" import uuid from datetime import datetime, timezone from sqlalchemy import DateTime, ForeignKey, String, Text from sqlalchemy.orm import Mapped, mapped_column from app.core.database import Base from app.core.types import JSONBType class PreMortemRecord(Base): """Pre-mortem 失败推演。""" __tablename__ = "pre_mortem_records" id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4())) company_id: Mapped[str] = mapped_column(String(36), ForeignKey("companies.id"), nullable=False, index=True) decision_context: Mapped[str | None] = mapped_column(Text, nullable=True, comment="决策上下文") failure_paths: Mapped[dict | None] = mapped_column(JSONBType, nullable=True, comment="失败路径列表") risk_checklist: Mapped[dict | None] = mapped_column(JSONBType, nullable=True, comment="风险清单") mitigations: Mapped[dict | None] = mapped_column(JSONBType, nullable=True, comment="缓解措施") created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), default=lambda: datetime.now(timezone.utc) ) class RedTeamRecord(Base): """Red Team 对抗分析。""" __tablename__ = "red_team_records" id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4())) company_id: Mapped[str] = mapped_column(String(36), ForeignKey("companies.id"), nullable=False, index=True) perspective: Mapped[str] = mapped_column(String(50), nullable=False, comment="competitor/pessimistic_investor/devils_advocate") analysis: Mapped[str | None] = mapped_column(Text, nullable=True, comment="对抗分析内容") vulnerabilities: Mapped[dict | None] = mapped_column(JSONBType, nullable=True, comment="发现的漏洞") counterarguments: Mapped[dict | None] = mapped_column(JSONBType, nullable=True, comment="反驳论点") created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), default=lambda: datetime.now(timezone.utc) )