"""download_credentials (S6: per-user, per-host yt-dlp cookie/auth store) Each user stores their OWN login cookies (Netscape cookies.txt) for an auth-walled download host (Facebook, Instagram, …), Fernet-encrypted at rest. A download of a yt-dlp-supported, auth-walled link on that host is retried with the acting user's cookie. Unique per (user_id, host_key) so a user holds at most one credential per host. Empty for every existing install; forward-only in practice (a downgrade just drops the table + its secrets). """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op revision: str = "0074_download_credentials" down_revision: Union[str, None] = "0073_saved_view_source" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: op.create_table( "download_credentials", sa.Column("id", sa.Integer(), primary_key=True), sa.Column( "user_id", sa.Integer(), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False, ), sa.Column("host_key", sa.String(length=64), nullable=False), sa.Column("cookies_enc", sa.Text(), nullable=False), sa.Column( "created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False ), sa.Column( "updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False ), sa.UniqueConstraint("user_id", "host_key", name="uq_download_credential"), ) op.create_index("ix_download_credentials_user_id", "download_credentials", ["user_id"]) def downgrade() -> None: op.drop_index("ix_download_credentials_user_id", table_name="download_credentials") op.drop_table("download_credentials")