"""
Copyright (c) 2015 Michael Bright and Bamboo HR LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

events_model

Revision ID: bf363c3a9ef0
Revises: e66b5abaa8c2
Create Date: 2017-10-20 17:25:24.391418

"""

# revision identifiers, used by Alembic.
from rapid.workflow.data.models import EventType

revision = 'bf363c3a9ef0'
down_revision = 'e66b5abaa8c2'
branch_labels = None
depends_on = None

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

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('event_types',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=100), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    mysql_engine='InnoDB'
    )
    op.create_index(op.f('ix_event_types_id'), 'event_types', ['id'], unique=False)
    op.create_table('pipeline_events',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('pipeline_id', sa.Integer(), nullable=False),
    sa.Column('event_type_id', sa.Integer(), nullable=False),
    sa.Column('conditional', sa.TEXT(), nullable=False),
    sa.Column('config', sa.TEXT(), nullable=False),
    sa.ForeignKeyConstraint(['pipeline_id'], ['pipelines.id'], ),
    sa.ForeignKeyConstraint(['event_type_id'], ['event_types.id'], ),
    sa.PrimaryKeyConstraint('id'),
    mysql_engine='InnoDB'
    )
    op.create_index(op.f('ix_pipeline_events_event_type_id'), 'pipeline_events', ['event_type_id'], unique=False)
    op.create_index(op.f('ix_pipeline_events_id'), 'pipeline_events', ['id'], unique=False)
    op.create_index(op.f('ix_pipeline_events_pipeline_id'), 'pipeline_events', ['pipeline_id'], unique=False)
    ### end Alembic commands ###

    op.bulk_insert(EventType.__table__, [
        {"id": 1, "name": "Remote Webhook", "active": True}
    ])


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_pipeline_events_pipeline_id'), table_name='pipeline_events')
    op.drop_index(op.f('ix_pipeline_events_id'), table_name='pipeline_events')
    op.drop_index(op.f('ix_pipeline_events_event_type_id'), table_name='pipeline_events')
    op.drop_table('pipeline_events')
    op.drop_index(op.f('ix_event_types_id'), table_name='event_types')
    op.drop_table('event_types')
    ### end Alembic commands ###
