"""initial keyserver Revision ID: a3ba52d02dec Revises: e4129c93e477 Create Date: 2016-03-30 15:28:32.036753 """ # revision identifiers, used by Alembic. revision = 'a3ba52d02dec' down_revision = 'e4129c93e477' from alembic import op import sqlalchemy as sa from util.migrate import UTF8LongText def upgrade(tables): op.create_table( 'servicekeyapproval', sa.Column('id', sa.Integer(), nullable=False), sa.Column('approver_id', sa.Integer(), nullable=True), sa.Column('approval_type', sa.String(length=255), nullable=False), sa.Column('approved_date', sa.DateTime(), nullable=False), sa.Column('notes', UTF8LongText(), nullable=False), sa.PrimaryKeyConstraint('id', name=op.f('pk_servicekeyapproval')), ) op.bulk_insert( tables.notificationkind, [{'name':'service_key_submitted'}], ) op.bulk_insert(tables.logentrykind, [ {'name':'service_key_create'}, {'name':'service_key_approve'}, {'name':'service_key_delete'}, {'name':'service_key_modify'}, {'name':'service_key_extend'}, {'name':'service_key_rotate'}, ]) op.create_index('servicekeyapproval_approval_type', 'servicekeyapproval', ['approval_type'], unique=False) op.create_index('servicekeyapproval_approver_id', 'servicekeyapproval', ['approver_id'], unique=False) op.create_table( 'servicekey', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=255), nullable=False), sa.Column('kid', sa.String(length=255), nullable=False), sa.Column('service', sa.String(length=255), nullable=False), sa.Column('jwk', UTF8LongText(), nullable=False), sa.Column('metadata', UTF8LongText(), nullable=False), sa.Column('created_date', sa.DateTime(), nullable=False), sa.Column('expiration_date', sa.DateTime(), nullable=True), sa.Column('rotation_duration', sa.Integer(), nullable=True), sa.Column('approval_id', sa.Integer(), nullable=True), sa.ForeignKeyConstraint(['approval_id'], ['servicekeyapproval.id'], name=op.f('fk_servicekey_approval_id_servicekeyapproval')), sa.PrimaryKeyConstraint('id', name=op.f('pk_servicekey')), ) op.create_index('servicekey_approval_id', 'servicekey', ['approval_id'], unique=False) op.create_index('servicekey_kid', 'servicekey', ['kid'], unique=True) op.create_index('servicekey_service', 'servicekey', ['service'], unique=False) op.add_column(u'notification', sa.Column('lookup_path', sa.String(length=255), nullable=True)) op.create_index('notification_lookup_path', 'notification', ['lookup_path'], unique=False) def downgrade(tables): op.execute(tables.logentrykind.delete().where(tables.logentrykind.c.name == op.inline_literal('service_key_create'))) op.execute(tables.logentrykind.delete().where(tables.logentrykind.c.name == op.inline_literal('service_key_approve'))) op.execute(tables.logentrykind.delete().where(tables.logentrykind.c.name == op.inline_literal('service_key_delete'))) op.execute(tables.logentrykind.delete().where(tables.logentrykind.c.name == op.inline_literal('service_key_modify'))) op.execute(tables.logentrykind.delete().where(tables.logentrykind.c.name == op.inline_literal('service_key_extend'))) op.execute(tables.logentrykind.delete().where(tables.logentrykind.c.name == op.inline_literal('service_key_rotate'))) op.drop_column(u'notification', 'lookup_path') op.drop_table('servicekey') op.drop_table('servicekeyapproval')