Files
tapehoard/backend/alembic/versions/33d682d2c089_add_splitting_support.py
T
2026-04-25 17:03:28 -04:00

66 lines
1.9 KiB
Python

"""add_splitting_support
Revision ID: 33d682d2c089
Revises: 5e867c5b4930
Create Date: 2026-04-23 20:47:53.406493
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = "33d682d2c089"
down_revision: Union[str, Sequence[str], None] = "5e867c5b4930"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# Columns might exist due to failed previous run
conn = op.get_bind()
columns = [c["name"] for c in sa.inspect(conn).get_columns("file_versions")]
if "is_split" not in columns:
op.add_column(
"file_versions",
sa.Column("is_split", sa.Boolean(), nullable=False, server_default="0"),
)
if "split_id" not in columns:
op.add_column(
"file_versions", sa.Column("split_id", sa.String(), nullable=True)
)
if "offset_start" not in columns:
op.add_column(
"file_versions",
sa.Column(
"offset_start", sa.BigInteger(), nullable=False, server_default="0"
),
)
if "offset_end" not in columns:
op.add_column(
"file_versions",
sa.Column(
"offset_end", sa.BigInteger(), nullable=False, server_default="0"
),
)
if "created_at" not in columns:
op.add_column(
"file_versions", sa.Column("created_at", sa.DateTime(), nullable=True)
)
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("file_versions", "created_at")
op.drop_column("file_versions", "offset_end")
op.drop_column("file_versions", "offset_start")
op.drop_column("file_versions", "split_id")
op.drop_column("file_versions", "is_split")
# ### end Alembic commands ###