"""A share link may open a folder Revision ID: 0108_folder_links Revises: 0107_link_token_at_rest Create Date: 2026-10-15 A `/watch` link opened one file. Now it may open one of its owner's own folders instead: the link's page lists what is in the folder when it is opened. `folder_id` sits beside `job_id`, exactly one of the two set; a folder's links go with the folder. The downgrade has nowhere to keep a folder link, so it deletes them: they stop opening. """ import sqlalchemy as sa from alembic import op revision: str = "0108_folder_links" down_revision: str | None = "0107_link_token_at_rest" branch_labels: str | None = None depends_on: str | None = None def upgrade() -> None: op.add_column( "download_links", sa.Column("folder_id", sa.Integer(), sa.ForeignKey("file_folders.id", ondelete="CASCADE")), ) op.create_index("ix_download_links_folder_id", "download_links", ["folder_id"]) op.alter_column("download_links", "job_id", nullable=True) op.create_check_constraint( "ck_download_link_target", "download_links", "(job_id IS NULL) <> (folder_id IS NULL)" ) def downgrade() -> None: op.execute("DELETE FROM download_links WHERE folder_id IS NOT NULL") op.drop_constraint("ck_download_link_target", "download_links", type_="check") op.alter_column("download_links", "job_id", nullable=False) op.drop_index("ix_download_links_folder_id", table_name="download_links") op.drop_column("download_links", "folder_id")