Implement FastAPI Temporal MVP pipeline
This commit is contained in:
61
alembic/env.py
Normal file
61
alembic/env.py
Normal file
@@ -0,0 +1,61 @@
|
||||
"""Alembic environment configuration."""
|
||||
|
||||
from logging.config import fileConfig
|
||||
|
||||
from alembic import context
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
|
||||
from app.config.settings import get_settings
|
||||
from app.infra.db.base import Base
|
||||
from app.infra.db.models.asset import AssetORM
|
||||
from app.infra.db.models.order import OrderORM
|
||||
from app.infra.db.models.review_task import ReviewTaskORM
|
||||
from app.infra.db.models.workflow_run import WorkflowRunORM
|
||||
from app.infra.db.models.workflow_step import WorkflowStepORM
|
||||
|
||||
del AssetORM, OrderORM, ReviewTaskORM, WorkflowRunORM, WorkflowStepORM
|
||||
|
||||
config = context.config
|
||||
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
config.set_main_option("sqlalchemy.url", get_settings().sync_database_url)
|
||||
target_metadata = Base.metadata
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
"""Run migrations in offline mode."""
|
||||
|
||||
context.configure(
|
||||
url=config.get_main_option("sqlalchemy.url"),
|
||||
target_metadata=target_metadata,
|
||||
literal_binds=True,
|
||||
dialect_opts={"paramstyle": "named"},
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
"""Run migrations in online mode."""
|
||||
|
||||
connectable = engine_from_config(
|
||||
config.get_section(config.config_ini_section, {}),
|
||||
prefix="sqlalchemy.",
|
||||
poolclass=pool.NullPool,
|
||||
)
|
||||
|
||||
with connectable.connect() as connection:
|
||||
context.configure(connection=connection, target_metadata=target_metadata)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
||||
|
||||
214
alembic/versions/20260326_0001_initial.py
Normal file
214
alembic/versions/20260326_0001_initial.py
Normal file
@@ -0,0 +1,214 @@
|
||||
"""initial schema
|
||||
|
||||
Revision ID: 20260326_0001
|
||||
Revises:
|
||||
Create Date: 2026-03-26 23:59:00.000000
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision: str = "20260326_0001"
|
||||
down_revision: str | None = None
|
||||
branch_labels: Sequence[str] | None = None
|
||||
depends_on: Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Create the initial application tables."""
|
||||
|
||||
op.create_table(
|
||||
"orders",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column("customer_level", sa.Enum("low", "mid", name="customerlevel", native_enum=False), nullable=False),
|
||||
sa.Column("service_mode", sa.Enum("auto_basic", "semi_pro", name="servicemode", native_enum=False), nullable=False),
|
||||
sa.Column(
|
||||
"status",
|
||||
sa.Enum(
|
||||
"created",
|
||||
"running",
|
||||
"waiting_review",
|
||||
"succeeded",
|
||||
"failed",
|
||||
"cancelled",
|
||||
name="orderstatus",
|
||||
native_enum=False,
|
||||
),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("model_id", sa.Integer(), nullable=False),
|
||||
sa.Column("pose_id", sa.Integer(), nullable=False),
|
||||
sa.Column("garment_asset_id", sa.Integer(), nullable=False),
|
||||
sa.Column("scene_ref_asset_id", sa.Integer(), nullable=False),
|
||||
sa.Column("final_asset_id", sa.Integer(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"assets",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column("order_id", sa.Integer(), sa.ForeignKey("orders.id"), nullable=False),
|
||||
sa.Column(
|
||||
"asset_type",
|
||||
sa.Enum(
|
||||
"prepared_model",
|
||||
"tryon",
|
||||
"scene",
|
||||
"texture",
|
||||
"face",
|
||||
"fusion",
|
||||
"qc_candidate",
|
||||
"final",
|
||||
name="assettype",
|
||||
native_enum=False,
|
||||
),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column(
|
||||
"step_name",
|
||||
sa.Enum(
|
||||
"prepare_model",
|
||||
"tryon",
|
||||
"scene",
|
||||
"texture",
|
||||
"face",
|
||||
"fusion",
|
||||
"qc",
|
||||
"export",
|
||||
"review",
|
||||
name="workflowstepname",
|
||||
native_enum=False,
|
||||
),
|
||||
nullable=True,
|
||||
),
|
||||
sa.Column("uri", sa.String(length=500), nullable=False),
|
||||
sa.Column("metadata_json", sa.JSON(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
op.create_index("ix_assets_order_id", "assets", ["order_id"])
|
||||
|
||||
op.create_table(
|
||||
"review_tasks",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column("order_id", sa.Integer(), sa.ForeignKey("orders.id"), nullable=False),
|
||||
sa.Column(
|
||||
"status",
|
||||
sa.Enum("pending", "submitted", name="reviewtaskstatus", native_enum=False),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column(
|
||||
"decision",
|
||||
sa.Enum(
|
||||
"approve",
|
||||
"rerun_scene",
|
||||
"rerun_face",
|
||||
"rerun_fusion",
|
||||
"reject",
|
||||
name="reviewdecision",
|
||||
native_enum=False,
|
||||
),
|
||||
nullable=True,
|
||||
),
|
||||
sa.Column("reviewer_id", sa.Integer(), nullable=True),
|
||||
sa.Column("selected_asset_id", sa.Integer(), nullable=True),
|
||||
sa.Column("comment", sa.Text(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
op.create_index("ix_review_tasks_order_id", "review_tasks", ["order_id"])
|
||||
|
||||
op.create_table(
|
||||
"workflow_runs",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column("order_id", sa.Integer(), sa.ForeignKey("orders.id"), nullable=False),
|
||||
sa.Column("workflow_id", sa.String(length=255), nullable=False),
|
||||
sa.Column("workflow_type", sa.String(length=255), nullable=False),
|
||||
sa.Column(
|
||||
"status",
|
||||
sa.Enum(
|
||||
"created",
|
||||
"running",
|
||||
"waiting_review",
|
||||
"succeeded",
|
||||
"failed",
|
||||
"cancelled",
|
||||
name="orderstatus",
|
||||
native_enum=False,
|
||||
),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column(
|
||||
"current_step",
|
||||
sa.Enum(
|
||||
"prepare_model",
|
||||
"tryon",
|
||||
"scene",
|
||||
"texture",
|
||||
"face",
|
||||
"fusion",
|
||||
"qc",
|
||||
"export",
|
||||
"review",
|
||||
name="workflowstepname",
|
||||
native_enum=False,
|
||||
),
|
||||
nullable=True,
|
||||
),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.UniqueConstraint("workflow_id"),
|
||||
)
|
||||
op.create_index("ix_workflow_runs_order_id", "workflow_runs", ["order_id"])
|
||||
|
||||
op.create_table(
|
||||
"workflow_steps",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column("workflow_run_id", sa.Integer(), sa.ForeignKey("workflow_runs.id"), nullable=False),
|
||||
sa.Column(
|
||||
"step_name",
|
||||
sa.Enum(
|
||||
"prepare_model",
|
||||
"tryon",
|
||||
"scene",
|
||||
"texture",
|
||||
"face",
|
||||
"fusion",
|
||||
"qc",
|
||||
"export",
|
||||
"review",
|
||||
name="workflowstepname",
|
||||
native_enum=False,
|
||||
),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column(
|
||||
"step_status",
|
||||
sa.Enum("pending", "running", "waiting", "succeeded", "failed", name="stepstatus", native_enum=False),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("input_json", sa.JSON(), nullable=True),
|
||||
sa.Column("output_json", sa.JSON(), nullable=True),
|
||||
sa.Column("error_message", sa.Text(), nullable=True),
|
||||
sa.Column("started_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("ended_at", sa.DateTime(timezone=True), nullable=True),
|
||||
)
|
||||
op.create_index("ix_workflow_steps_workflow_run_id", "workflow_steps", ["workflow_run_id"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Drop the application tables."""
|
||||
|
||||
op.drop_index("ix_workflow_steps_workflow_run_id", table_name="workflow_steps")
|
||||
op.drop_table("workflow_steps")
|
||||
op.drop_index("ix_workflow_runs_order_id", table_name="workflow_runs")
|
||||
op.drop_table("workflow_runs")
|
||||
op.drop_index("ix_review_tasks_order_id", table_name="review_tasks")
|
||||
op.drop_table("review_tasks")
|
||||
op.drop_index("ix_assets_order_id", table_name="assets")
|
||||
op.drop_table("assets")
|
||||
op.drop_table("orders")
|
||||
Reference in New Issue
Block a user