Files
auto-virtual-tryon/app/infra/db/models/library_resource_file.py

38 lines
1.5 KiB
Python

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