"""make Revision hierarchical and remove RevisionMode

Revision ID: cc8d01a1af42
Revises: <PASSWORD>
Create Date: 2018-12-15 07:05:38.562794

"""

# revision identifiers, used by Alembic.
revision = 'cc8d01a1af42'
down_revision = 'e527d9001345'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('revision_variable',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('revision_id', sa.Integer(), nullable=True),
    sa.Column('variable_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['revision_id'], ['revisions.id'], ),
    sa.ForeignKeyConstraint(['variable_id'], ['variables.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('revisions', sa.Column('category', sa.String(length=128), nullable=True))
    op.add_column('revisions', sa.Column('renames', sa.JSON(), nullable=True))
    op.drop_column('revisions', 'mode')
    op.execute("DROP TYPE revisionmode;")
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    revisionmode = postgresql.ENUM('NEW', 'CON', 'DIS', 'DEL', 'MOD', 'FIT', name='revisionmode', create_type=False)
    revisionmode.create(op.get_bind())
    op.add_column('revisions', sa.Column('mode', revisionmode, autoincrement=False, nullable=False))
    op.drop_column('revisions', 'renames')
    op.drop_column('revisions', 'category')
    op.drop_table('revision_variable')
    # ### end Alembic commands ###
