54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
from sqlalchemy import Column, Integer, String, ForeignKey, Text, DateTime, Boolean
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class AssetCollection(Base):
|
|
"""A curated collection or pack of 3D models and assets."""
|
|
__tablename__ = "asset_collections"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
title = Column(String(255), nullable=False, index=True)
|
|
description = Column(Text, nullable=True)
|
|
theme = Column(String(64), nullable=False, default="general", index=True)
|
|
thumbnail_url = Column(String(512), nullable=True)
|
|
owner_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
|
is_public = Column(Boolean, default=True, nullable=False, index=True)
|
|
tags = Column(String(512), nullable=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
owner = relationship("User", back_populates="asset_collections")
|
|
items = relationship(
|
|
"CollectionAsset",
|
|
back_populates="collection",
|
|
cascade="all, delete-orphan",
|
|
order_by="CollectionAsset.sort_order",
|
|
)
|
|
|
|
|
|
class CollectionAsset(Base):
|
|
"""Join entity linking an Asset to an AssetCollection with ordering."""
|
|
__tablename__ = "collection_assets"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
collection_id = Column(
|
|
Integer,
|
|
ForeignKey("asset_collections.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
asset_id = Column(
|
|
Integer,
|
|
ForeignKey("assets.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
sort_order = Column(Integer, default=0, nullable=False)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
collection = relationship("AssetCollection", back_populates="items")
|
|
asset = relationship("Asset")
|