"""Migrate SQLA 2 and remove redundant columns

Revision ID: 3a53a9fb26ab
Revises: 07dcbe6c4f0e
Create Date: 2023-10-15 09:39:16.449419

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = '3a53a9fb26ab'
down_revision = '07dcbe6c4f0e'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('playlists', 'query')
    op.drop_column('playlists', 'sort_column')
    op.alter_column('tracks', 'title',
               existing_type=mysql.VARCHAR(length=256),
               nullable=False)
    op.alter_column('tracks', 'artist',
               existing_type=mysql.VARCHAR(length=256),
               nullable=False)
    op.alter_column('tracks', 'duration',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=False)
    op.alter_column('tracks', 'start_gap',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=False)
    op.alter_column('tracks', 'fade_at',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=False)
    op.alter_column('tracks', 'silence_at',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=False)
    op.alter_column('tracks', 'mtime',
               existing_type=mysql.FLOAT(),
               nullable=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('tracks', 'mtime',
               existing_type=mysql.FLOAT(),
               nullable=True)
    op.alter_column('tracks', 'silence_at',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=True)
    op.alter_column('tracks', 'fade_at',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=True)
    op.alter_column('tracks', 'start_gap',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=True)
    op.alter_column('tracks', 'duration',
               existing_type=mysql.INTEGER(display_width=11),
               nullable=True)
    op.alter_column('tracks', 'artist',
               existing_type=mysql.VARCHAR(length=256),
               nullable=True)
    op.alter_column('tracks', 'title',
               existing_type=mysql.VARCHAR(length=256),
               nullable=True)
    op.add_column('playlists', sa.Column('sort_column', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.add_column('playlists', sa.Column('query', mysql.VARCHAR(length=256), nullable=True))
    # ### end Alembic commands ###
