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,45 @@
"""Library resource ORM model."""
from __future__ import annotations
from sqlalchemy import Enum, Integer, JSON, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.domain.enums import LibraryResourceStatus, LibraryResourceType
from app.infra.db.base import Base, TimestampMixin
class LibraryResourceORM(TimestampMixin, Base):
"""Persisted library resource independent from order-generated assets."""
__tablename__ = "library_resources"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
resource_type: Mapped[LibraryResourceType] = mapped_column(
Enum(LibraryResourceType, native_enum=False),
nullable=False,
index=True,
)
name: Mapped[str] = mapped_column(String(255), nullable=False)
description: Mapped[str | None] = mapped_column(Text, nullable=True)
tags: Mapped[list[str]] = mapped_column(JSON, nullable=False, default=list)
status: Mapped[LibraryResourceStatus] = mapped_column(
Enum(LibraryResourceStatus, native_enum=False),
nullable=False,
default=LibraryResourceStatus.ACTIVE,
index=True,
)
gender: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True)
age_group: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True)
pose_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
environment: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True)
category: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
cover_file_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
original_file_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
files = relationship(
"LibraryResourceFileORM",
back_populates="resource",
lazy="selectin",
cascade="all, delete-orphan",
)

View File

@@ -0,0 +1,37 @@
"""Library resource file ORM model."""
from __future__ import annotations
from sqlalchemy import Enum, ForeignKey, Integer, String
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.domain.enums import LibraryFileRole
from app.infra.db.base import Base, TimestampMixin
class LibraryResourceFileORM(TimestampMixin, Base):
"""Persisted uploaded file metadata for a library resource."""
__tablename__ = "library_resource_files"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
resource_id: Mapped[int] = mapped_column(
ForeignKey("library_resources.id"),
nullable=False,
index=True,
)
file_role: Mapped[LibraryFileRole] = mapped_column(
Enum(LibraryFileRole, native_enum=False),
nullable=False,
index=True,
)
storage_key: Mapped[str] = mapped_column(String(500), nullable=False)
public_url: Mapped[str] = mapped_column(String(500), nullable=False)
bucket: Mapped[str] = mapped_column(String(255), nullable=False)
mime_type: Mapped[str] = mapped_column(String(255), nullable=False)
size_bytes: Mapped[int] = mapped_column(Integer, nullable=False)
sort_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
width: Mapped[int | None] = mapped_column(Integer, nullable=True)
height: Mapped[int | None] = mapped_column(Integer, nullable=True)
resource = relationship("LibraryResourceORM", back_populates="files")

View File

@@ -27,12 +27,11 @@ class OrderORM(TimestampMixin, Base):
default=OrderStatus.CREATED,
)
model_id: Mapped[int] = mapped_column(Integer, nullable=False)
pose_id: Mapped[int] = mapped_column(Integer, nullable=False)
pose_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
garment_asset_id: Mapped[int] = mapped_column(Integer, nullable=False)
scene_ref_asset_id: Mapped[int] = mapped_column(Integer, nullable=False)
scene_ref_asset_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
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")