"""library: a resume point per user and library item The library player opened every item at 0:00. `library_states` keeps where a user stopped, per job (their own download, or one shared with them) — the same shape as `video_states`' position, without a status: the library has no "watched". It starts empty; the downgrade drops it. """ import sqlalchemy as sa from alembic import op revision: str = "0099_library_states" down_revision: str | None = "0098_drop_demo_account" branch_labels: str | None = None depends_on: str | None = None def upgrade() -> None: op.create_table( "library_states", sa.Column("id", sa.Integer(), primary_key=True), sa.Column( "user_id", sa.Integer(), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False, ), sa.Column( "job_id", sa.Integer(), sa.ForeignKey("download_jobs.id", ondelete="CASCADE"), nullable=False, ), sa.Column("position_seconds", sa.Integer(), nullable=False), sa.Column("progress_updated_at", sa.DateTime(timezone=True), nullable=False), sa.UniqueConstraint("user_id", "job_id", name="uq_library_user_job"), ) op.create_index("ix_library_states_job_id", "library_states", ["job_id"]) def downgrade() -> None: op.drop_index("ix_library_states_job_id", table_name="library_states") op.drop_table("library_states")