"""refacotring db to work with multiple music provider

Revision ID: 18d056f49f59
Revises: d4fef99d5d3c
Create Date: 2024-11-29 22:51:41.271688

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '18d056f49f59'
down_revision = 'd4fef99d5d3c'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('playlist', schema=None) as batch_op:
        batch_op.add_column(sa.Column('provider_playlist_id', sa.String(length=120), nullable=False))
        batch_op.add_column(sa.Column('provider_uri', sa.String(length=120), nullable=False))
        batch_op.add_column(sa.Column('provider_id', sa.String(length=20), nullable=True))
        batch_op.drop_constraint('playlist_spotify_playlist_id_key', type_='unique')
        batch_op.drop_constraint('playlist_spotify_uri_key', type_='unique')
        batch_op.create_unique_constraint(None, ['provider_uri'])
        batch_op.create_unique_constraint(None, ['provider_playlist_id'])
        batch_op.drop_column('spotify_playlist_id')
        batch_op.drop_column('spotify_uri')

    with op.batch_alter_table('track', schema=None) as batch_op:
        batch_op.add_column(sa.Column('provider_track_id', sa.String(length=120), nullable=False))
        batch_op.add_column(sa.Column('provider_uri', sa.String(length=120), nullable=False))
        batch_op.add_column(sa.Column('provider_id', sa.String(length=20), nullable=True))
        batch_op.drop_constraint('track_spotify_track_id_key', type_='unique')
        batch_op.drop_constraint('track_spotify_uri_key', type_='unique')
        batch_op.create_unique_constraint(None, ['provider_track_id'])
        batch_op.create_unique_constraint(None, ['provider_uri'])
        batch_op.drop_column('spotify_track_id')
        batch_op.drop_column('spotify_uri')

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('track', schema=None) as batch_op:
        batch_op.add_column(sa.Column('spotify_uri', sa.VARCHAR(length=120), autoincrement=False, nullable=False))
        batch_op.add_column(sa.Column('spotify_track_id', sa.VARCHAR(length=120), autoincrement=False, nullable=False))
        batch_op.drop_constraint(None, type_='unique')
        batch_op.drop_constraint(None, type_='unique')
        batch_op.create_unique_constraint('track_spotify_uri_key', ['spotify_uri'])
        batch_op.create_unique_constraint('track_spotify_track_id_key', ['spotify_track_id'])
        batch_op.drop_column('provider_id')
        batch_op.drop_column('provider_uri')
        batch_op.drop_column('provider_track_id')

    with op.batch_alter_table('playlist', schema=None) as batch_op:
        batch_op.add_column(sa.Column('spotify_uri', sa.VARCHAR(length=120), autoincrement=False, nullable=False))
        batch_op.add_column(sa.Column('spotify_playlist_id', sa.VARCHAR(length=120), autoincrement=False, nullable=False))
        batch_op.drop_constraint(None, type_='unique')
        batch_op.drop_constraint(None, type_='unique')
        batch_op.create_unique_constraint('playlist_spotify_uri_key', ['spotify_uri'])
        batch_op.create_unique_constraint('playlist_spotify_playlist_id_key', ['spotify_playlist_id'])
        batch_op.drop_column('provider_id')
        batch_op.drop_column('provider_uri')
        batch_op.drop_column('provider_playlist_id')

    # ### end Alembic commands ###
