Files
you-music/backend/alembic/versions/c1fd223a3556_add_file_tracking_columns.py
T
2025-10-30 22:35:02 +11:00

45 lines
1.5 KiB
Python

"""Add file tracking columns
Revision ID: c1fd223a3556
Revises: 01209c730b33
Create Date: 2025-10-30 21:48:22.894324
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'c1fd223a3556'
down_revision: Union[str, Sequence[str], None] = '01209c730b33'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('music', schema=None) as batch_op:
batch_op.add_column(sa.Column('file_format', sa.String(), nullable=True))
batch_op.add_column(sa.Column('file_location', sa.String(), nullable=True))
batch_op.add_column(sa.Column('file_exists', sa.Boolean(), nullable=True))
batch_op.add_column(sa.Column('last_scanned_at', sa.DateTime(), nullable=True))
# Set default value for existing records
op.execute("UPDATE music SET file_exists = 1 WHERE file_exists IS NULL")
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('music', schema=None) as batch_op:
batch_op.drop_column('last_scanned_at')
batch_op.drop_column('file_exists')
batch_op.drop_column('file_location')
batch_op.drop_column('file_format')
# ### end Alembic commands ###