"""error_links_1

Revision ID: 237b922fac1
Revises: 47360dc61f2
Create Date: 2015-11-19 22:29:15.084611

"""

# revision identifiers, used by Alembic.
revision = '237b922fac1'
down_revision = '47360dc61f2'

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('error', sa.Column('session_id', sa.Integer(), nullable=True))
    op.add_column('error', sa.Column('test_id', sa.Integer(), nullable=True))
    op.create_index(op.f('ix_error_session_id'), 'error', ['session_id'], unique=False)
    op.create_index(op.f('ix_error_test_id'), 'error', ['test_id'], unique=False)
    op.create_foreign_key('error_test_id', 'error', 'test', ['test_id'], ['id'], ondelete='CASCADE')
    op.create_foreign_key('error_session_id', 'error', 'session', ['session_id'], ['id'], ondelete='CASCADE')
    op.execute('update error set session_id = (select session_id from session_error where error_id = error.id)')
    op.execute('update error set test_id = (select test_id from test_error where error_id = error.id)')
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('error_test_id', 'error', type_='foreignkey')
    op.drop_constraint('error_session_id', 'error', type_='foreignkey')
    op.drop_index(op.f('ix_error_test_id'), table_name='error')
    op.drop_index(op.f('ix_error_session_id'), table_name='error')
    op.drop_column('error', 'test_id')
    op.drop_column('error', 'session_id')
    ### end Alembic commands ###
