Add movie/series ratings and watchlist

Builds on the accounts foundation: PUT/DELETE a rating (0.5-10.0) or a
watchlist entry on any movie or series, all scoped to the bearer token's
own user, plus GET /account/ratings|watchlist/{movies,series} to list
them back. Both are polymorphic entity_type/entity_id tables, same shape
as watch_provider_offerings and trending_entries, so movie and series
share one repository/router each rather than duplicating per type.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
NixReaper
2026-09-06 10:47:41 -05:00
co-authored by Claude Sonnet 5
parent a38c2074a6
commit 0ab31a314c
20 changed files with 1043 additions and 6 deletions
@@ -0,0 +1,76 @@
"""ratings and watchlist
Revision ID: 0005_ratings_and_watchlist
Revises: 0004_users
Create Date: 2026-09-06
Adds the ratings and watchlist_entries tables (section 17, additive) --
both polymorphic across movie/series, same entity_type/entity_id shape
as watch_provider_offerings and trending_entries.
"""
from __future__ import annotations
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
revision: str = "0005_ratings_and_watchlist"
down_revision: str | None = "0004_users"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
op.create_table(
"ratings",
sa.Column("id", sa.Uuid(), primary_key=True),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column("user_id", sa.Uuid(), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False),
sa.Column("entity_type", sa.String(30), nullable=False),
sa.Column("entity_id", sa.Uuid(), nullable=False),
sa.Column("value", sa.Float(), nullable=False),
sa.UniqueConstraint("user_id", "entity_type", "entity_id", name="uq_ratings_user_id"),
)
op.create_index("ix_ratings_entity", "ratings", ["entity_type", "entity_id"])
op.create_table(
"watchlist_entries",
sa.Column("id", sa.Uuid(), primary_key=True),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column("user_id", sa.Uuid(), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False),
sa.Column("entity_type", sa.String(30), nullable=False),
sa.Column("entity_id", sa.Uuid(), nullable=False),
sa.UniqueConstraint("user_id", "entity_type", "entity_id", name="uq_watchlist_entries_user_id"),
)
op.create_index("ix_watchlist_entries_user", "watchlist_entries", ["user_id", "entity_type"])
def downgrade() -> None:
op.drop_index("ix_watchlist_entries_user", table_name="watchlist_entries")
op.drop_table("watchlist_entries")
op.drop_index("ix_ratings_entity", table_name="ratings")
op.drop_table("ratings")