goon/app/models/blacklist.py
jtrzupek c8baa11604 feat(api): device-scope user state (favorites/progress/blacklists)
Public instance has no accounts, so all user state was GLOBAL in DB — new users
saw/overwrote each other's (and Jan's) favorites, watched badges and blacklists
(bug 2026-06-10). Add device_id (VARCHAR 64) to 9 state tables with composite PK
(device_id, entity_id); app sends X-Device-Id header (get_device_id dep). All
favorites/scene-favorites/blacklist/watch + scene&movie list/detail (is_favorite,
watched, blacklist-hide) now filter by device. Existing rows backfilled to
'legacy-shared'; POST /me/adopt-legacy reassigns them to the caller once. Old
clients (no header) map to legacy-shared so they keep working until OTA updates.

Migration 0022: add col, backfill, composite PK. Verified on prod: 967 progress
rows preserved, device isolation holds (new device sees none of legacy state).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 08:58:01 +02:00

50 lines
1.6 KiB
Python

"""Blacklists — performer/studio/tag globalne ukrywania."""
from __future__ import annotations
import uuid
from datetime import datetime
from sqlalchemy import DateTime, ForeignKey, String, func
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import Base
class BlacklistedPerformer(Base):
__tablename__ = "blacklisted_performers"
device_id: Mapped[str] = mapped_column(String(64), primary_key=True)
performer_id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
ForeignKey("performers.id", ondelete="CASCADE"),
primary_key=True,
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)
class BlacklistedStudio(Base):
__tablename__ = "blacklisted_studios"
device_id: Mapped[str] = mapped_column(String(64), primary_key=True)
studio_id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
ForeignKey("studios.id", ondelete="CASCADE"),
primary_key=True,
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)
class BlacklistedTag(Base):
__tablename__ = "blacklisted_tags"
device_id: Mapped[str] = mapped_column(String(64), primary_key=True)
tag_id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
ForeignKey("tags.id", ondelete="CASCADE"),
primary_key=True,
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)