<reponame>xumiao/supernorm
"""adding more revision modes and license placeholder

Revision ID: 6<PASSWORD>d3e2e1fd
Revises: <PASSWORD>
Create Date: 2018-12-09 04:06:19.541874

"""

revision = '6<PASSWORD>'
down_revision = '<PASSWORD>'

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


old_options = ('NEW', 'OR', 'AND')
new_options = ('NEW', 'CON', 'DIS', 'DEL', 'MOD', 'FIT')

old_type = postgresql.ENUM(*old_options, name='revisionmode')
new_type = postgresql.ENUM(*new_options, name='revisionmode')
tmp_type = postgresql.ENUM(*new_options, name='_revisionmode')

tcr = sa.sql.table('revisions', sa.Column('mode', new_type, nullable=False))


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('licenses',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=256), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('lambdas', sa.Column('license_id', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'lambdas', 'licenses', ['license_id'], ['id'])

    tmp_type.create(op.get_bind(), checkfirst=False)
    op.execute('ALTER TABLE revisions ALTER COLUMN mode TYPE _revisionmode'
               ' USING mode::text::_revisionmode')
    old_type.drop(op.get_bind(), checkfirst=False)
    # Create and convert to the "new" mode type
    new_type.create(op.get_bind(), checkfirst=False)
    op.execute('ALTER TABLE revisions ALTER COLUMN mode TYPE revisionmode'
               ' USING mode::text::revisionmode')
    tmp_type.drop(op.get_bind(), checkfirst=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'lambdas', type_='foreignkey')
    op.drop_column('lambdas', 'license_id')
    op.drop_table('licenses')

    # Create a tempoary "_revisionmode" type, convert and drop the "new" type
    tmp_type.create(op.get_bind(), checkfirst=False)
    op.execute('ALTER TABLE revisions ALTER COLUMN mode TYPE _revisionmode'
               ' USING mode::text::_revisionmode')
    new_type.drop(op.get_bind(), checkfirst=False)
    # Create and convert to the "old" mode type
    old_type.create(op.get_bind(), checkfirst=False)
    op.execute('ALTER TABLE revisions ALTER COLUMN mode TYPE revisionmode'
               ' USING mode::text::revisionmode')
    tmp_type.drop(op.get_bind(), checkfirst=False)
    # ### end Alembic commands ###

"""adding more revision modes and license placeholder

Revision ID: 6<PASSWORD>d3e2e1fd
Revises: <PASSWORD>
Create Date: 2018-12-09 04:06:19.541874

"""

revision = '6<PASSWORD>'
down_revision = '<PASSWORD>'

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


old_options = ('NEW', 'OR', 'AND')
new_options = ('NEW', 'CON', 'DIS', 'DEL', 'MOD', 'FIT')

old_type = postgresql.ENUM(*old_options, name='revisionmode')
new_type = postgresql.ENUM(*new_options, name='revisionmode')
tmp_type = postgresql.ENUM(*new_options, name='_revisionmode')

tcr = sa.sql.table('revisions', sa.Column('mode', new_type, nullable=False))


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('licenses',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=256), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('lambdas', sa.Column('license_id', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'lambdas', 'licenses', ['license_id'], ['id'])

    tmp_type.create(op.get_bind(), checkfirst=False)
    op.execute('ALTER TABLE revisions ALTER COLUMN mode TYPE _revisionmode'
               ' USING mode::text::_revisionmode')
    old_type.drop(op.get_bind(), checkfirst=False)
    # Create and convert to the "new" mode type
    new_type.create(op.get_bind(), checkfirst=False)
    op.execute('ALTER TABLE revisions ALTER COLUMN mode TYPE revisionmode'
               ' USING mode::text::revisionmode')
    tmp_type.drop(op.get_bind(), checkfirst=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'lambdas', type_='foreignkey')
    op.drop_column('lambdas', 'license_id')
    op.drop_table('licenses')

    # Create a tempoary "_revisionmode" type, convert and drop the "new" type
    tmp_type.create(op.get_bind(), checkfirst=False)
    op.execute('ALTER TABLE revisions ALTER COLUMN mode TYPE _revisionmode'
               ' USING mode::text::_revisionmode')
    new_type.drop(op.get_bind(), checkfirst=False)
    # Create and convert to the "old" mode type
    old_type.create(op.get_bind(), checkfirst=False)
    op.execute('ALTER TABLE revisions ALTER COLUMN mode TYPE revisionmode'
               ' USING mode::text::revisionmode')
    tmp_type.drop(op.get_bind(), checkfirst=False)
    # ### end Alembic commands ###
adding more revision modes and license placeholder  Revision ID: 6<PASSWORD>d3e2e1fd Revises: <PASSWORD> Create Date: 2018-12-09 04:06:19.541874 # ### commands auto generated by Alembic - please adjust! ### # Create and convert to the "new" mode type # ### end Alembic commands ### # ### commands auto generated by Alembic - please adjust! ### # Create a tempoary "_revisionmode" type, convert and drop the "new" type # Create and convert to the "old" mode type # ### end Alembic commands ###