feat(progress): track per-user resume position server-side

Add position_seconds (+progress_updated_at) to video_states so watch progress
survives across devices and can drive a feed filter. New POST
/api/videos/{id}/progress checkpoints the player position (clearing trivially
-early and near-finished positions). Feed serialize exposes position_seconds and
a show=in_progress filter lists started-but-unfinished videos. Un-marking
'watched' now keeps a stored position instead of deleting the row.
This commit is contained in:
npeter83 2026-06-14 18:40:05 +02:00
parent d791d577a0
commit 6520f35d88
3 changed files with 126 additions and 1 deletions

View file

@ -0,0 +1,44 @@
"""watch progress: resume position on video_states
Revision ID: 0010_watch_progress
Revises: 0009_quota_events
Create Date: 2026-06-14
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
revision: str = "0010_watch_progress"
down_revision: Union[str, None] = "0009_quota_events"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.add_column(
"video_states",
sa.Column(
"position_seconds",
sa.Integer(),
nullable=False,
server_default="0",
),
)
op.add_column(
"video_states",
sa.Column("progress_updated_at", sa.DateTime(timezone=True), nullable=True),
)
# Partial index to keep the "in progress" feed filter cheap (only started videos).
op.create_index(
"ix_video_states_in_progress",
"video_states",
["user_id"],
postgresql_where=sa.text("position_seconds > 0"),
)
def downgrade() -> None:
op.drop_index("ix_video_states_in_progress", table_name="video_states")
op.drop_column("video_states", "progress_updated_at")
op.drop_column("video_states", "position_seconds")