Implement FastAPI Temporal MVP pipeline

This commit is contained in:
Codex
2026-03-27 00:10:28 +08:00
commit cc03da8a94
52 changed files with 3619 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
"""Asset ORM model."""
from typing import Any
from sqlalchemy import Enum, ForeignKey, Integer, JSON, String
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.domain.enums import AssetType, WorkflowStepName
from app.infra.db.base import Base, TimestampMixin
class AssetORM(TimestampMixin, Base):
"""Persisted generated asset."""
__tablename__ = "assets"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
order_id: Mapped[int] = mapped_column(ForeignKey("orders.id"), nullable=False, index=True)
asset_type: Mapped[AssetType] = mapped_column(
Enum(AssetType, native_enum=False),
nullable=False,
)
step_name: Mapped[WorkflowStepName | None] = mapped_column(
Enum(WorkflowStepName, native_enum=False),
nullable=True,
)
uri: Mapped[str] = mapped_column(String(500), nullable=False)
metadata_json: Mapped[dict[str, Any] | None] = mapped_column(JSON, nullable=True)
order = relationship("OrderORM", back_populates="assets")

View File

@@ -0,0 +1,38 @@
"""Order ORM model."""
from sqlalchemy import Enum, Integer
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.domain.enums import CustomerLevel, OrderStatus, ServiceMode
from app.infra.db.base import Base, TimestampMixin
class OrderORM(TimestampMixin, Base):
"""Persisted order record."""
__tablename__ = "orders"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
customer_level: Mapped[CustomerLevel] = mapped_column(
Enum(CustomerLevel, native_enum=False),
nullable=False,
)
service_mode: Mapped[ServiceMode] = mapped_column(
Enum(ServiceMode, native_enum=False),
nullable=False,
)
status: Mapped[OrderStatus] = mapped_column(
Enum(OrderStatus, native_enum=False),
nullable=False,
default=OrderStatus.CREATED,
)
model_id: Mapped[int] = mapped_column(Integer, nullable=False)
pose_id: Mapped[int] = mapped_column(Integer, nullable=False)
garment_asset_id: Mapped[int] = mapped_column(Integer, nullable=False)
scene_ref_asset_id: Mapped[int] = mapped_column(Integer, nullable=False)
final_asset_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
assets = relationship("AssetORM", back_populates="order", lazy="selectin")
review_tasks = relationship("ReviewTaskORM", back_populates="order", lazy="selectin")
workflow_runs = relationship("WorkflowRunORM", back_populates="order", lazy="selectin")

View File

@@ -0,0 +1,31 @@
"""Review task ORM model."""
from sqlalchemy import Enum, ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.domain.enums import ReviewDecision, ReviewTaskStatus
from app.infra.db.base import Base, TimestampMixin
class ReviewTaskORM(TimestampMixin, Base):
"""Persisted review task."""
__tablename__ = "review_tasks"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
order_id: Mapped[int] = mapped_column(ForeignKey("orders.id"), nullable=False, index=True)
status: Mapped[ReviewTaskStatus] = mapped_column(
Enum(ReviewTaskStatus, native_enum=False),
nullable=False,
default=ReviewTaskStatus.PENDING,
)
decision: Mapped[ReviewDecision | None] = mapped_column(
Enum(ReviewDecision, native_enum=False),
nullable=True,
)
reviewer_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
selected_asset_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
comment: Mapped[str | None] = mapped_column(Text, nullable=True)
order = relationship("OrderORM", back_populates="review_tasks")

View File

@@ -0,0 +1,36 @@
"""Workflow run ORM model."""
from sqlalchemy import Enum, ForeignKey, Integer, String
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.domain.enums import OrderStatus, WorkflowStepName
from app.infra.db.base import Base, TimestampMixin
class WorkflowRunORM(TimestampMixin, Base):
"""Persisted workflow execution state."""
__tablename__ = "workflow_runs"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
order_id: Mapped[int] = mapped_column(ForeignKey("orders.id"), nullable=False, index=True)
workflow_id: Mapped[str] = mapped_column(String(255), nullable=False, unique=True)
workflow_type: Mapped[str] = mapped_column(String(255), nullable=False)
status: Mapped[OrderStatus] = mapped_column(
Enum(OrderStatus, native_enum=False),
nullable=False,
default=OrderStatus.CREATED,
)
current_step: Mapped[WorkflowStepName | None] = mapped_column(
Enum(WorkflowStepName, native_enum=False),
nullable=True,
)
order = relationship("OrderORM", back_populates="workflow_runs")
steps = relationship(
"WorkflowStepORM",
back_populates="workflow_run",
lazy="selectin",
order_by="WorkflowStepORM.started_at",
)

View File

@@ -0,0 +1,42 @@
"""Workflow step ORM model."""
from datetime import datetime
from typing import Any
from sqlalchemy import DateTime, Enum, ForeignKey, Integer, JSON, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.domain.enums import StepStatus, WorkflowStepName
from app.infra.db.base import Base, utc_now
class WorkflowStepORM(Base):
"""Persisted workflow step execution record."""
__tablename__ = "workflow_steps"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
workflow_run_id: Mapped[int] = mapped_column(
ForeignKey("workflow_runs.id"),
nullable=False,
index=True,
)
step_name: Mapped[WorkflowStepName] = mapped_column(
Enum(WorkflowStepName, native_enum=False),
nullable=False,
)
step_status: Mapped[StepStatus] = mapped_column(
Enum(StepStatus, native_enum=False),
nullable=False,
)
input_json: Mapped[dict[str, Any] | None] = mapped_column(JSON, nullable=True)
output_json: Mapped[dict[str, Any] | None] = mapped_column(JSON, nullable=True)
error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
started_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
default=utc_now,
nullable=False,
)
ended_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
workflow_run = relationship("WorkflowRunORM", back_populates="steps")