cmvr-visual/backend/app/models/workflows.py
zhanghao 88cf14d794 feat: consolidate story studio and editable automatic production
Restructure backend and frontend modules; add story, library, and editor schema migrations.

Support editable automatic production, manual confirmation modes, account and user lifecycle management, compact container scrolling, consistent forms, and per-task result previews.

Update inference and TTS scheduling, deployment guidance, and regression coverage; remove obsolete standalone pages and temporary acceptance artifacts.
2026-11-14 14:07:26 +08:00

110 lines
6.0 KiB
Python

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 WorkflowDraft(Base):
__tablename__ = "visual_drafts"
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=new_id)
folder_id: Mapped[str | None] = mapped_column(
ForeignKey("visual_folders.id", ondelete="SET NULL"), nullable=True, index=True
)
owner_id: Mapped[str] = mapped_column(String(32), ForeignKey("visual_users.id"), index=True)
name: Mapped[str] = mapped_column(String(255))
kind: Mapped[str] = mapped_column(String(48), default="three_shot")
spec: Mapped[dict] = mapped_column(JSON, default=dict)
editor_manifest: Mapped[dict | None] = mapped_column(JSON, nullable=True)
revision: Mapped[int] = mapped_column(Integer, default=1)
version: Mapped[int] = mapped_column(Integer, default=1)
current_run_id: Mapped[str | None] = mapped_column(String(32), nullable=True)
created_at: Mapped[datetime] = mapped_column(Timestamp, default=utcnow)
updated_at: Mapped[datetime] = mapped_column(Timestamp, default=utcnow)
deleted_at: Mapped[datetime | None] = mapped_column(Timestamp, nullable=True)
class WorkflowRun(Base):
__tablename__ = "visual_workflow_runs"
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=new_id)
folder_id: Mapped[str | None] = mapped_column(
ForeignKey("visual_folders.id", ondelete="SET NULL"), nullable=True, index=True
)
output_folder_id: Mapped[str | None] = mapped_column(
ForeignKey("visual_folders.id", ondelete="SET NULL"), nullable=True, index=True
)
owner_id: Mapped[str] = mapped_column(String(32), ForeignKey("visual_users.id"), index=True)
draft_id: Mapped[str] = mapped_column(String(32))
draft_revision: Mapped[int] = mapped_column(Integer)
spec_snapshot: Mapped[dict] = mapped_column(JSON, default=dict)
spec_hash: Mapped[str] = mapped_column(String(64))
run_kind: Mapped[str] = mapped_column(String(32), default="legacy", server_default="legacy")
output_goal: Mapped[str] = mapped_column(String(16), default="film", server_default="film")
base_run_id: Mapped[str | None] = mapped_column(String(32), nullable=True)
source_draft_version: Mapped[int | None] = mapped_column(Integer, nullable=True)
plan_snapshot: Mapped[dict | None] = mapped_column(JSON, nullable=True)
result_manifest: Mapped[dict | None] = mapped_column(JSON, nullable=True)
apply_state: Mapped[str | None] = mapped_column(String(16), nullable=True)
execution_mode: Mapped[str] = mapped_column(String(16), default="interactive")
state: Mapped[str] = mapped_column(String(32), default="queued")
desired_state: Mapped[str] = mapped_column(String(16), default="run")
hold_reasons: Mapped[list] = mapped_column(JSON, default=list)
version: Mapped[int] = mapped_column(Integer, default=1)
batch_id: Mapped[str | None] = mapped_column(String(32), nullable=True)
batch_item_index: Mapped[int | None] = mapped_column(Integer, nullable=True)
current_output_asset_id: Mapped[str | None] = mapped_column(String(32), nullable=True)
error_json: Mapped[dict | None] = mapped_column(JSON, nullable=True)
created_at: Mapped[datetime] = mapped_column(Timestamp, default=utcnow)
started_at: Mapped[datetime | None] = mapped_column(Timestamp, nullable=True)
finished_at: Mapped[datetime | None] = mapped_column(Timestamp, nullable=True)
deleted_at: Mapped[datetime | None] = mapped_column(Timestamp, nullable=True)
class WorkflowStep(Base):
__tablename__ = "visual_workflow_steps"
__table_args__ = (UniqueConstraint("run_id", "step_key"),)
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=new_id)
run_id: Mapped[str] = mapped_column(String(32))
step_key: Mapped[str] = mapped_column(String(32))
kind: Mapped[str] = mapped_column(String(48))
dependencies: Mapped[list] = mapped_column(JSON, default=list)
semantic_input_hash: Mapped[str] = mapped_column(String(64))
selected_job_id: Mapped[str | None] = mapped_column(String(32), nullable=True)
state: Mapped[str] = mapped_column(String(32), default="waiting")
recipe_json: Mapped[dict | None] = mapped_column(JSON, nullable=True)
resolved_input_json: Mapped[dict | None] = mapped_column(JSON, nullable=True)
result_json: Mapped[dict | None] = mapped_column(JSON, nullable=True)
explicit_attempt: Mapped[int] = mapped_column(Integer, default=0)
version: Mapped[int] = mapped_column(Integer, default=1)
class Batch(Base):
__tablename__ = "visual_batches"
hold_reasons: Mapped[list] = mapped_column(JSON, default=list)
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)
name: Mapped[str] = mapped_column(String(255))
spec_snapshot: Mapped[dict] = mapped_column(JSON, default=dict)
state: Mapped[str] = mapped_column(String(32), default="queued")
desired_state: Mapped[str] = mapped_column(String(16), default="run")
version: Mapped[int] = mapped_column(Integer, default=1)
created_at: Mapped[datetime] = mapped_column(Timestamp, default=utcnow)
finished_at: Mapped[datetime | None] = mapped_column(Timestamp, nullable=True)
deleted_at: Mapped[datetime | None] = mapped_column(Timestamp, nullable=True)
class BatchItem(Base):
__tablename__ = "visual_batch_items"
__table_args__ = (UniqueConstraint("batch_id", "item_index"),)
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=new_id)
batch_id: Mapped[str] = mapped_column(String(32))
item_index: Mapped[int] = mapped_column(Integer)
target_kind: Mapped[str] = mapped_column(String(16))
target_id: Mapped[str] = mapped_column(String(32))
spec_json: Mapped[dict] = mapped_column(JSON, default=dict)
state: Mapped[str] = mapped_column(String(32), default="queued")