"""Make session table generic.

Revision ID: 6e2a520d2782
Revises: 45438cc39f6d
Create Date: 2017-04-13 21:16:03.808257

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

# revision identifiers, used by Alembic.
revision = '6e2a520d2782'
down_revision = '45438cc39f6d'
branch_labels = None
depends_on = None


def upgrade():
    conn = op.get_bind()

    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('session', sa.Column('id', sa.Integer(), nullable=False))
    op.add_column('session', sa.Column('type', sa.String(length=32), nullable=False))

    sql = "UPDATE session SET id = userid, type = 'userid'"
    conn.execute(text(sql), {})

    op.drop_column('session', 'userid')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('session', sa.Column('userid', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False))
    op.drop_column('session', 'type')
    op.drop_column('session', 'id')
    # ### end Alembic commands ###
