feat: add resource library and real image workflow

This commit is contained in:
afei A
2026-03-29 00:24:29 +08:00
parent eeaff269eb
commit 04da401ab4
38 changed files with 3033 additions and 117 deletions

View File

@@ -0,0 +1,92 @@
"""resource library schema
Revision ID: 20260328_0003
Revises: 20260327_0002
Create Date: 2026-03-28 10:20:00.000000
"""
from collections.abc import Sequence
from alembic import op
import sqlalchemy as sa
revision: str = "20260328_0003"
down_revision: str | None = "20260327_0002"
branch_labels: Sequence[str] | None = None
depends_on: Sequence[str] | None = None
def upgrade() -> None:
"""Create the resource-library tables."""
op.create_table(
"library_resources",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
sa.Column(
"resource_type",
sa.Enum("model", "scene", "garment", name="libraryresourcetype", native_enum=False),
nullable=False,
),
sa.Column("name", sa.String(length=255), nullable=False),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("tags", sa.JSON(), nullable=False),
sa.Column(
"status",
sa.Enum("active", "archived", name="libraryresourcestatus", native_enum=False),
nullable=False,
),
sa.Column("gender", sa.String(length=32), nullable=True),
sa.Column("age_group", sa.String(length=32), nullable=True),
sa.Column("pose_id", sa.Integer(), nullable=True),
sa.Column("environment", sa.String(length=32), nullable=True),
sa.Column("category", sa.String(length=128), nullable=True),
sa.Column("cover_file_id", sa.Integer(), nullable=True),
sa.Column("original_file_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_index("ix_library_resources_resource_type", "library_resources", ["resource_type"])
op.create_index("ix_library_resources_status", "library_resources", ["status"])
op.create_index("ix_library_resources_gender", "library_resources", ["gender"])
op.create_index("ix_library_resources_age_group", "library_resources", ["age_group"])
op.create_index("ix_library_resources_environment", "library_resources", ["environment"])
op.create_index("ix_library_resources_category", "library_resources", ["category"])
op.create_table(
"library_resource_files",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
sa.Column("resource_id", sa.Integer(), sa.ForeignKey("library_resources.id"), nullable=False),
sa.Column(
"file_role",
sa.Enum("original", "thumbnail", "gallery", name="libraryfilerole", native_enum=False),
nullable=False,
),
sa.Column("storage_key", sa.String(length=500), nullable=False),
sa.Column("public_url", sa.String(length=500), nullable=False),
sa.Column("bucket", sa.String(length=255), nullable=False),
sa.Column("mime_type", sa.String(length=255), nullable=False),
sa.Column("size_bytes", sa.Integer(), nullable=False),
sa.Column("sort_order", sa.Integer(), nullable=False),
sa.Column("width", sa.Integer(), nullable=True),
sa.Column("height", 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_index("ix_library_resource_files_resource_id", "library_resource_files", ["resource_id"])
op.create_index("ix_library_resource_files_file_role", "library_resource_files", ["file_role"])
def downgrade() -> None:
"""Drop the resource-library tables."""
op.drop_index("ix_library_resource_files_file_role", table_name="library_resource_files")
op.drop_index("ix_library_resource_files_resource_id", table_name="library_resource_files")
op.drop_table("library_resource_files")
op.drop_index("ix_library_resources_category", table_name="library_resources")
op.drop_index("ix_library_resources_environment", table_name="library_resources")
op.drop_index("ix_library_resources_age_group", table_name="library_resources")
op.drop_index("ix_library_resources_gender", table_name="library_resources")
op.drop_index("ix_library_resources_status", table_name="library_resources")
op.drop_index("ix_library_resources_resource_type", table_name="library_resources")
op.drop_table("library_resources")

View File

@@ -0,0 +1,25 @@
"""Make order pose_id optional for MVP.
Revision ID: 20260328_0004
Revises: 20260328_0003
Create Date: 2026-03-28 11:08:00.000000
"""
from alembic import op
import sqlalchemy as sa
revision = "20260328_0004"
down_revision = "20260328_0003"
branch_labels = None
depends_on = None
def upgrade() -> None:
with op.batch_alter_table("orders") as batch_op:
batch_op.alter_column("pose_id", existing_type=sa.Integer(), nullable=True)
def downgrade() -> None:
with op.batch_alter_table("orders") as batch_op:
batch_op.alter_column("pose_id", existing_type=sa.Integer(), nullable=False)

View File

@@ -0,0 +1,25 @@
"""Make order scene_ref_asset_id optional for MVP.
Revision ID: 20260328_0005
Revises: 20260328_0004
Create Date: 2026-03-28 14:20:00.000000
"""
from alembic import op
import sqlalchemy as sa
revision = "20260328_0005"
down_revision = "20260328_0004"
branch_labels = None
depends_on = None
def upgrade() -> None:
with op.batch_alter_table("orders") as batch_op:
batch_op.alter_column("scene_ref_asset_id", existing_type=sa.Integer(), nullable=True)
def downgrade() -> None:
with op.batch_alter_table("orders") as batch_op:
batch_op.alter_column("scene_ref_asset_id", existing_type=sa.Integer(), nullable=False)