feat(notifications): durable per-user inbox (P1) + maintenance schema
Add a server-backed notification center that coexists with the client-side transient bell: a per-user `notifications` table (type/title/body/data JSON/ read/dismissed), a `/api/me/notifications` CRUD API (list, unread_count, read, read_all, dismiss, clear), and a left-nav inbox module with a live unread badge polled via useLiveQuery. Known types render trilingual text from type+data (English stored text is the fallback); read rows are trimmed past a soft cap. Also adds the schema the maintenance job builds on: videos.list?part=status columns (embeddable/privacy_status/upload_status) and the validation lifecycle columns (last_checked_at, unavailable_since, unavailable_reason). Page-id validation is centralized in one PAGES source of truth (isPage) so the new page survives reload without a second allowlist to keep in sync.
This commit is contained in:
parent
a11a8db278
commit
b9a3a9012d
14 changed files with 649 additions and 22 deletions
43
backend/alembic/versions/0016_video_maintenance.py
Normal file
43
backend/alembic/versions/0016_video_maintenance.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
"""video maintenance / validation columns
|
||||
|
||||
Revision ID: 0016_video_maintenance
|
||||
Revises: 0015_scheduler_settings
|
||||
Create Date: 2026-06-18
|
||||
|
||||
Adds the columns the maintenance/validation job needs to detect and retire unplayable
|
||||
videos: videos.list?part=status fields (embeddable / privacy_status / upload_status) plus
|
||||
the validation lifecycle (last_checked_at for rolling re-validation; unavailable_since +
|
||||
unavailable_reason to flag a video as currently unplayable — hidden from the feed
|
||||
immediately, hard-deleted after a grace period). Purely additive; all columns nullable.
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "0016_video_maintenance"
|
||||
down_revision: Union[str, None] = "0015_scheduler_settings"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column("videos", sa.Column("embeddable", sa.Boolean(), nullable=True))
|
||||
op.add_column("videos", sa.Column("privacy_status", sa.String(length=16), nullable=True))
|
||||
op.add_column("videos", sa.Column("upload_status", sa.String(length=16), nullable=True))
|
||||
op.add_column("videos", sa.Column("last_checked_at", sa.DateTime(timezone=True), nullable=True))
|
||||
op.add_column("videos", sa.Column("unavailable_since", sa.DateTime(timezone=True), nullable=True))
|
||||
op.add_column("videos", sa.Column("unavailable_reason", sa.String(length=24), nullable=True))
|
||||
op.create_index("ix_videos_last_checked_at", "videos", ["last_checked_at"])
|
||||
op.create_index("ix_videos_unavailable_since", "videos", ["unavailable_since"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_videos_unavailable_since", table_name="videos")
|
||||
op.drop_index("ix_videos_last_checked_at", table_name="videos")
|
||||
op.drop_column("videos", "unavailable_reason")
|
||||
op.drop_column("videos", "unavailable_since")
|
||||
op.drop_column("videos", "last_checked_at")
|
||||
op.drop_column("videos", "upload_status")
|
||||
op.drop_column("videos", "privacy_status")
|
||||
op.drop_column("videos", "embeddable")
|
||||
59
backend/alembic/versions/0017_notifications.py
Normal file
59
backend/alembic/versions/0017_notifications.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
"""per-user notification inbox (phase 1)
|
||||
|
||||
Revision ID: 0017_notifications
|
||||
Revises: 0016_video_maintenance
|
||||
Create Date: 2026-06-18
|
||||
|
||||
Adds the durable, server-backed per-user notification table behind the inbox module. The
|
||||
JSON payload column is named `data` (SQLAlchemy's declarative Base reserves `metadata`).
|
||||
First producer is the maintenance job's batched "videos removed" notice. Coexists with the
|
||||
existing client-side transient bell.
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "0017_notifications"
|
||||
down_revision: Union[str, None] = "0016_video_maintenance"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"notifications",
|
||||
sa.Column("id", sa.Integer(), primary_key=True),
|
||||
sa.Column(
|
||||
"user_id",
|
||||
sa.Integer(),
|
||||
sa.ForeignKey("users.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("type", sa.String(length=32), nullable=False),
|
||||
sa.Column("title", sa.String(length=255), nullable=False),
|
||||
sa.Column("body", sa.Text(), nullable=True),
|
||||
sa.Column("data", sa.JSON(), nullable=True),
|
||||
sa.Column("read", sa.Boolean(), nullable=False, server_default="false"),
|
||||
sa.Column("dismissed", sa.Boolean(), nullable=False, server_default="false"),
|
||||
sa.Column(
|
||||
"created_at", sa.DateTime(timezone=True), server_default=sa.func.now()
|
||||
),
|
||||
)
|
||||
op.create_index("ix_notifications_user_id", "notifications", ["user_id"])
|
||||
op.create_index("ix_notifications_type", "notifications", ["type"])
|
||||
op.create_index("ix_notifications_read", "notifications", ["read"])
|
||||
op.create_index("ix_notifications_created_at", "notifications", ["created_at"])
|
||||
# Fast unread-badge count + inbox listing per user.
|
||||
op.create_index(
|
||||
"ix_notifications_user_read", "notifications", ["user_id", "read"]
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_notifications_user_read", table_name="notifications")
|
||||
op.drop_index("ix_notifications_created_at", table_name="notifications")
|
||||
op.drop_index("ix_notifications_read", table_name="notifications")
|
||||
op.drop_index("ix_notifications_type", table_name="notifications")
|
||||
op.drop_index("ix_notifications_user_id", table_name="notifications")
|
||||
op.drop_table("notifications")
|
||||
Loading…
Add table
Add a link
Reference in a new issue