cmvr-visual/backend/app/models/stories.py

46 lines
2.7 KiB
Python
Raw Permalink Normal View History

"""候选保留冻结输入,选择追加记录;普通草稿 JSON 无法伪造批准。"""
from datetime import datetime
from sqlalchemy import ForeignKey, Integer, JSON, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base, Timestamp, new_id, utcnow
class ShotCandidate(Base):
__tablename__ = "visual_shot_candidates"
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=new_id)
owner_id: Mapped[str] = mapped_column(String(32), ForeignKey("visual_users.id"), index=True)
draft_id: Mapped[str] = mapped_column(String(32), ForeignKey("visual_drafts.id"), index=True)
shot_id: Mapped[str] = mapped_column(String(32), index=True)
kind: Mapped[str] = mapped_column(String(16))
source_kind: Mapped[str] = mapped_column(String(16))
job_id: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True)
asset_id: Mapped[str | None] = mapped_column(String(32), nullable=True)
asset_sha256: Mapped[str | None] = mapped_column(String(64), nullable=True)
context_hash: Mapped[str] = mapped_column(String(64))
generation_hash: Mapped[str] = mapped_column(String(64))
created_revision: Mapped[int] = mapped_column(Integer)
version: Mapped[int] = mapped_column(Integer, default=1)
state: Mapped[str] = mapped_column(String(32), default="queued")
plan_json: Mapped[dict] = mapped_column(JSON, default=dict)
error_json: Mapped[dict | None] = mapped_column(JSON, nullable=True)
batch_id: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True)
created_at: Mapped[datetime] = mapped_column(Timestamp, default=utcnow)
deleted_at: Mapped[datetime | None] = mapped_column(Timestamp, nullable=True)
class ShotSelection(Base):
__tablename__ = "visual_shot_selections"
__table_args__ = (UniqueConstraint("draft_id", "shot_id", "kind", "version"),)
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=new_id)
owner_id: Mapped[str] = mapped_column(String(32), ForeignKey("visual_users.id"), index=True)
draft_id: Mapped[str] = mapped_column(String(32), ForeignKey("visual_drafts.id"), index=True)
shot_id: Mapped[str] = mapped_column(String(32), index=True)
kind: Mapped[str] = mapped_column(String(16))
candidate_id: Mapped[str | None] = mapped_column(String(32), nullable=True)
asset_id: Mapped[str | None] = mapped_column(String(32), nullable=True)
decision_json: Mapped[dict] = mapped_column(JSON, default=dict)
context_hash: Mapped[str] = mapped_column(String(64))
version: Mapped[int] = mapped_column(Integer, default=1)
created_at: Mapped[datetime] = mapped_column(Timestamp, default=utcnow)