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.
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
"""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")
|