"""Change User id type to string 

Revision ID: 58c319e84d94
Revises: a15b1085162f
Create Date: 2021-05-04 01:10:37.401748

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '58c319e84d94'
down_revision = 'a15b1085162f'
branch_labels = None
depends_on = None

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('tracks_user_id_fkey', 'tracks', type_='foreignkey')
    op.drop_constraint('musictaste_user_id_fkey', 'musictaste', type_='foreignkey')
    op.drop_constraint('rightswipes_swiper_fkey', 'rightswipes', type_='foreignkey')
    op.drop_constraint('rightswipes_swipee_fkey', 'rightswipes', type_='foreignkey')
    
    op.alter_column('users', 'id',
               existing_type=sa.INTEGER(),
               type_=sa.String(),
               existing_nullable=False,
               existing_server_default=sa.text("nextval('users_id_seq'::regclass)"))
    op.alter_column('musictaste', 'user_id',
               existing_type=sa.INTEGER(),
               type_=sa.String(),
               existing_nullable=True)
    op.alter_column('rightswipes', 'swipee',
               existing_type=sa.INTEGER(),
               type_=sa.String(),
               existing_nullable=False)
    op.alter_column('rightswipes', 'swiper',
               existing_type=sa.INTEGER(),
               type_=sa.String(),
               existing_nullable=False)
    op.alter_column('tracks', 'user_id',
               existing_type=sa.INTEGER(),
               type_=sa.String(),
               existing_nullable=True)
    
    op.create_foreign_key("tracks_user_id_fkey", "tracks", "users", ["user_id"], ["id"], ondelete='CASCADE')
    op.create_foreign_key("musictaste_user_id_fkey", "musictaste", "users", ["user_id"], ["id"], ondelete='CASCADE')
    op.create_foreign_key("rightswipes_swiper_fkey", "rightswipes", "users", ["swiper"], ["id"], ondelete='CASCADE')
    op.create_foreign_key("rightswipes_swipee_fkey", "rightswipes", "users", ["swipee"], ["id"], ondelete='CASCADE')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('tracks_user_id_fkey', 'tracks', type_='foreignkey')
    op.drop_constraint('musictaste_user_id_fkey', 'musictaste', type_='foreignkey')
    op.drop_constraint('rightswipes_swiper_fkey', 'rightswipes', type_='foreignkey')
    op.drop_constraint('rightswipes_swipee_fkey', 'rightswipes', type_='foreignkey')
    
    op.alter_column('users', 'id',
               existing_type=sa.String(),
               type_=sa.INTEGER(),
               existing_nullable=False,
               existing_server_default=sa.text("nextval('users_id_seq'::regclass)"))
    op.alter_column('tracks', 'user_id',
               existing_type=sa.String(),
               type_=sa.INTEGER(),
               existing_nullable=True)
    op.alter_column('rightswipes', 'swiper',
               existing_type=sa.String(),
               type_=sa.INTEGER(),
               existing_nullable=False)
    op.alter_column('rightswipes', 'swipee',
               existing_type=sa.String(),
               type_=sa.INTEGER(),
               existing_nullable=False)
    op.alter_column('musictaste', 'user_id',
               existing_type=sa.String(),
               type_=sa.INTEGER(),
               existing_nullable=True)

    op.create_foreign_key("tracks_user_id_fkey", "tracks", "users", ["user_id"], ["id"], ondelete='CASCADE')
    op.create_foreign_key("musictaste_user_id_fkey", "musictaste", "users", ["user_id"], ["id"], ondelete='CASCADE')
    op.create_foreign_key("rightswipes_swiper_fkey", "rightswipes", "users", ["swiper"], ["id"], ondelete='CASCADE')
    op.create_foreign_key("rightswipes_swipee_fkey", "rightswipes", "users", ["swipee"], ["id"], ondelete='CASCADE')
    # ### end Alembic commands ###
