siftlode/backend/alembic/versions/0034_blocked_channels.py
npeter83 f27f31b6db feat(search): ephemeral results, count selector, blocklist, new-first ordering (backend)
- Live-search results stay ephemeral: the discovery-cleanup job now also reclaims un-kept
  via_search videos (no watch state / not playlisted / channel not subscribed) after a grace
  period (search_grace_days), and POST /api/search/clear discards a given result set 'as if
  never added' (drops the user's search-finds + deletes the now-orphaned, un-kept videos).
  Admin POST /api/admin/purge-discovery runs it on demand (grace 0).
- Count selector: GET /api/search/youtube gains a 'limit' — the free scrape source pages
  through continuations until that many results are gathered (no manual load-more); the API
  source stays one ≤50 page (cost).
- Per-user channel blocklist (migration 0034 blocked_channels): block/unblock/list endpoints;
  blocked channels' videos are dropped from live search before ingest and hidden from the feed
  / Library / explore / channel page; explore refuses a blocked channel.
- New-first ordering: results you already have (subscribed channel, watched/in-progress/saved/
  playlisted) sink below genuinely-new discoveries, preserving relevance within each group.
2026-07-01 00:42:32 +02:00

46 lines
1.8 KiB
Python

"""per-user blocked channels (YouTube search / feed / explore)
Revision ID: 0034_blocked_channels
Revises: 0033_channel_explore
Create Date: 2026-07-01
Adds the `blocked_channels` table: a per-user blocklist. Videos from a blocked channel are
never shown in that user's live YouTube search (and not ingested), and are hidden from their
feed / explore views. Per-user, so one user's block doesn't affect anyone else.
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
revision: str = "0034_blocked_channels"
down_revision: Union[str, None] = "0033_channel_explore"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
"blocked_channels",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("user_id", sa.Integer(), nullable=False),
sa.Column("channel_id", sa.String(length=32), nullable=False),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
sa.ForeignKeyConstraint(["channel_id"], ["channels.id"], ondelete="CASCADE"),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("user_id", "channel_id", name="uq_user_blocked_channel"),
)
op.create_index("ix_blocked_channels_user_id", "blocked_channels", ["user_id"])
op.create_index("ix_blocked_channels_channel_id", "blocked_channels", ["channel_id"])
def downgrade() -> None:
op.drop_index("ix_blocked_channels_channel_id", table_name="blocked_channels")
op.drop_index("ix_blocked_channels_user_id", table_name="blocked_channels")
op.drop_table("blocked_channels")