60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
"""Collections/franchises as first-class entities (e.g. "Alien", "MCU")."""
|
|||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import uuid
|
||
|
|
|
||
|
|
from sqlalchemy import ForeignKey, Integer, String, Text
|
||
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
||
|
|
|
||
|
|
from app.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin
|
||
|
|
|
||
|
|
|
||
|
|
class Collection(Base, UUIDPrimaryKeyMixin, TimestampMixin):
|
||
|
|
__tablename__ = "collections"
|
||
|
|
|
||
|
|
name: Mapped[str] = mapped_column(String(300), nullable=False, index=True)
|
||
|
|
overview: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||
|
|
slug: Mapped[str] = mapped_column(String(350), unique=True, nullable=False)
|
||
|
|
|
||
|
|
|
||
|
|
class CollectionMovie(Base):
|
||
|
|
__tablename__ = "collection_movies"
|
||
|
|
|
||
|
|
collection_id: Mapped[uuid.UUID] = mapped_column(
|
||
|
|
ForeignKey("collections.id", ondelete="CASCADE"), primary_key=True
|
||
|
|
)
|
||
|
|
movie_id: Mapped[uuid.UUID] = mapped_column(
|
||
|
|
ForeignKey("movies.id", ondelete="CASCADE"), primary_key=True
|
||
|
|
)
|
||
|
|
sort_order: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||
|
|
|
||
|
|
|
||
|
|
class CollectionSeries(Base):
|
||
|
|
__tablename__ = "collection_series"
|
||
|
|
|
||
|
|
collection_id: Mapped[uuid.UUID] = mapped_column(
|
||
|
|
ForeignKey("collections.id", ondelete="CASCADE"), primary_key=True
|
||
|
|
)
|
||
|
|
series_id: Mapped[uuid.UUID] = mapped_column(
|
||
|
|
ForeignKey("series.id", ondelete="CASCADE"), primary_key=True
|
||
|
|
)
|
||
|
|
sort_order: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||
|
|
|
||
|
|
|
||
|
|
class CollectionRelation(Base):
|
||
|
|
"""Relationships between collections (e.g. shared universe)."""
|
||
|
|
|
||
|
|
__tablename__ = "collection_relations"
|
||
|
|
|
||
|
|
collection_id: Mapped[uuid.UUID] = mapped_column(
|
||
|
|
ForeignKey("collections.id", ondelete="CASCADE"), primary_key=True
|
||
|
|
)
|
||
|
|
related_collection_id: Mapped[uuid.UUID] = mapped_column(
|
||
|
|
ForeignKey("collections.id", ondelete="CASCADE"), primary_key=True
|
||
|
|
)
|
||
|
|
relation_type: Mapped[str] = mapped_column(String(50), default="related", nullable=False)
|
||
|
|
|
||
|
|
|
||
|
|
__all__ = ["Collection", "CollectionMovie", "CollectionSeries", "CollectionRelation"]
|