"""TaskResult: l'esito registrato da un task 'check' (OK/NOK) o 'note' (#54 #55).""" from datetime import datetime from typing import Optional from sqlalchemy import DateTime, Enum, ForeignKey, Integer, JSON, Text, func from sqlalchemy.orm import Mapped, mapped_column from src.backend.database import Base TASK_OUTCOMES = ("ok", "nok", "done") class TaskResult(Base): __tablename__ = "task_results" id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) task_id: Mapped[int] = mapped_column( Integer, ForeignKey("recipe_tasks.id", ondelete="CASCADE"), nullable=False, index=True, ) # Copiata dal task: la versione in cui l'esito e' stato dato non cambia piu'. version_id: Mapped[int] = mapped_column( Integer, ForeignKey("recipe_versions.id"), nullable=False, index=True ) production_run_id: Mapped[Optional[int]] = mapped_column( Integer, ForeignKey("production_runs.id", ondelete="SET NULL"), nullable=True, index=True, ) user_id: Mapped[int] = mapped_column( Integer, ForeignKey("users.id"), nullable=False ) outcome: Mapped[str] = mapped_column( Enum(*TASK_OUTCOMES, name="task_outcome_enum"), nullable=False ) note: Mapped[Optional[str]] = mapped_column(Text, nullable=True) # {chiave del campo: valore stringa}; allegati: [{key, path, name}] values: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True) attachments: Mapped[Optional[list]] = mapped_column(JSON, nullable=True) created_at: Mapped[datetime] = mapped_column( DateTime, nullable=False, server_default=func.now() ) __table_args__ = ({"mysql_engine": "InnoDB", "mysql_charset": "utf8mb4"},) def __repr__(self) -> str: return f""