"""Asset ORM model.""" from __future__ import annotations from typing import Any from sqlalchemy import Boolean, Enum, ForeignKey, Integer, JSON, String from sqlalchemy.orm import Mapped, mapped_column, relationship from app.domain.enums import AssetType, WorkflowStepName from app.infra.db.base import Base, TimestampMixin class AssetORM(TimestampMixin, Base): """Persisted generated asset.""" __tablename__ = "assets" id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) order_id: Mapped[int] = mapped_column(ForeignKey("orders.id"), nullable=False, index=True) asset_type: Mapped[AssetType] = mapped_column( Enum(AssetType, native_enum=False), nullable=False, ) step_name: Mapped[WorkflowStepName | None] = mapped_column( Enum(WorkflowStepName, native_enum=False), nullable=True, ) parent_asset_id: Mapped[int | None] = mapped_column( ForeignKey("assets.id"), nullable=True, index=True, ) root_asset_id: Mapped[int | None] = mapped_column(Integer, nullable=True, index=True) version_no: Mapped[int] = mapped_column(Integer, nullable=False, default=0) is_current_version: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False) uri: Mapped[str] = mapped_column(String(500), nullable=False) metadata_json: Mapped[dict[str, Any] | None] = mapped_column(JSON, nullable=True) order = relationship("OrderORM", back_populates="assets")