Files
auto-virtual-tryon/alembic/versions/20260328_0003_resource_library.py

93 lines
4.3 KiB
Python

"""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")