"""added task tracker

Revision ID: 75bd00cd3edc
Revises: efc3b5068a72
Create Date: 2018-08-16 14:09:48.055595

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '75bd00cd3edc'
down_revision = 'efc3b5068a72'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('block_task_meta',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('task_id', sa.Text(), nullable=True),
    sa.Column('task_name', sa.Text(), nullable=False),
    sa.Column('state', sa.Text(), nullable=False),
    sa.Column('block_number', sa.Numeric(), nullable=False),
    sa.Column('block_hash', sa.String(length=66), nullable=True),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_block_task_meta'))
    )
    op.alter_column('logs', 'address',
               existing_type=sa.VARCHAR(length=42),
               nullable=False)
    op.drop_constraint('fk_logs_transaction_hash_transactions', 'logs', type_='foreignkey')
    op.drop_constraint('fk_logs_block_number_blocks', 'logs', type_='foreignkey')
    op.create_foreign_key(op.f('fk_logs_transaction_hash_transactions'), 'logs', 'transactions', ['transaction_hash'], ['transaction_hash'], ondelete='CASCADE')
    op.create_foreign_key(op.f('fk_logs_block_number_blocks'), 'logs', 'blocks', ['block_number'], ['block_number'], ondelete='CASCADE')
    op.drop_constraint('fk_meta_info_last_pushed_block_blocks', 'meta_info', type_='foreignkey')
    op.create_foreign_key(op.f('fk_meta_info_last_pushed_block_blocks'), 'meta_info', 'blocks', ['last_pushed_block'], ['block_number'], ondelete='CASCADE')
    op.drop_constraint('fk_receipts_transaction_hash_transactions', 'receipts', type_='foreignkey')
    op.drop_constraint('fk_receipts_block_number_blocks', 'receipts', type_='foreignkey')
    op.create_foreign_key(op.f('fk_receipts_transaction_hash_transactions'), 'receipts', 'transactions', ['transaction_hash'], ['transaction_hash'], ondelete='CASCADE')
    op.create_foreign_key(op.f('fk_receipts_block_number_blocks'), 'receipts', 'blocks', ['block_number'], ['block_number'], ondelete='CASCADE')
    op.alter_column('state_diff', 'address',
               existing_type=sa.VARCHAR(length=42),
               nullable=False)
    op.drop_constraint('fk_state_diff_block_number_blocks', 'state_diff', type_='foreignkey')
    op.drop_constraint('fk_state_diff_transaction_hash_transactions', 'state_diff', type_='foreignkey')
    op.create_foreign_key(op.f('fk_state_diff_block_number_blocks'), 'state_diff', 'blocks', ['block_number'], ['block_number'], ondelete='CASCADE')
    op.create_foreign_key(op.f('fk_state_diff_transaction_hash_transactions'), 'state_diff', 'transactions', ['transaction_hash'], ['transaction_hash'], ondelete='CASCADE')
    op.drop_constraint('fk_storage_address_state', 'storage', type_='foreignkey')
    op.create_foreign_key(op.f('fk_storage_address_state'), 'storage', 'state', ['address'], ['address'], ondelete='CASCADE')
    op.drop_constraint('fk_storage_diff_block_number_blocks', 'storage_diff', type_='foreignkey')
    op.drop_constraint('fk_storage_diff_transaction_hash_transactions', 'storage_diff', type_='foreignkey')
    op.drop_constraint('fk_storage_diff_state_diff_id_state_diff', 'storage_diff', type_='foreignkey')
    op.create_foreign_key(op.f('fk_storage_diff_block_number_blocks'), 'storage_diff', 'blocks', ['block_number'], ['block_number'], ondelete='CASCADE')
    op.create_foreign_key(op.f('fk_storage_diff_transaction_hash_transactions'), 'storage_diff', 'transactions', ['transaction_hash'], ['transaction_hash'], ondelete='CASCADE')
    op.create_foreign_key(op.f('fk_storage_diff_state_diff_id_state_diff'), 'storage_diff', 'state_diff', ['state_diff_id'], ['id'], ondelete='CASCADE')
    op.drop_constraint('fk_traces_transaction_hash_transactions', 'traces', type_='foreignkey')
    op.drop_constraint('fk_traces_block_number_blocks', 'traces', type_='foreignkey')
    op.create_foreign_key(op.f('fk_traces_transaction_hash_transactions'), 'traces', 'transactions', ['transaction_hash'], ['transaction_hash'], ondelete='CASCADE')
    op.create_foreign_key(op.f('fk_traces_block_number_blocks'), 'traces', 'blocks', ['block_number'], ['block_number'], ondelete='CASCADE')
    op.drop_constraint('fk_transactions_block_number_blocks', 'transactions', type_='foreignkey')
    op.create_foreign_key(op.f('fk_transactions_block_number_blocks'), 'transactions', 'blocks', ['block_number'], ['block_number'], ondelete='CASCADE')
    op.drop_constraint('fk_uncles_current_blocknumber_blocks', 'uncles', type_='foreignkey')
    op.create_foreign_key(op.f('fk_uncles_current_blocknumber_blocks'), 'uncles', 'blocks', ['current_blocknumber'], ['block_number'], ondelete='CASCADE')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(op.f('fk_uncles_current_blocknumber_blocks'), 'uncles', type_='foreignkey')
    op.create_foreign_key('fk_uncles_current_blocknumber_blocks', 'uncles', 'blocks', ['current_blocknumber'], ['block_number'])
    op.drop_constraint(op.f('fk_transactions_block_number_blocks'), 'transactions', type_='foreignkey')
    op.create_foreign_key('fk_transactions_block_number_blocks', 'transactions', 'blocks', ['block_number'], ['block_number'])
    op.drop_constraint(op.f('fk_traces_block_number_blocks'), 'traces', type_='foreignkey')
    op.drop_constraint(op.f('fk_traces_transaction_hash_transactions'), 'traces', type_='foreignkey')
    op.create_foreign_key('fk_traces_block_number_blocks', 'traces', 'blocks', ['block_number'], ['block_number'])
    op.create_foreign_key('fk_traces_transaction_hash_transactions', 'traces', 'transactions', ['transaction_hash'], ['transaction_hash'])
    op.drop_constraint(op.f('fk_storage_diff_state_diff_id_state_diff'), 'storage_diff', type_='foreignkey')
    op.drop_constraint(op.f('fk_storage_diff_transaction_hash_transactions'), 'storage_diff', type_='foreignkey')
    op.drop_constraint(op.f('fk_storage_diff_block_number_blocks'), 'storage_diff', type_='foreignkey')
    op.create_foreign_key('fk_storage_diff_state_diff_id_state_diff', 'storage_diff', 'state_diff', ['state_diff_id'], ['id'])
    op.create_foreign_key('fk_storage_diff_transaction_hash_transactions', 'storage_diff', 'transactions', ['transaction_hash'], ['transaction_hash'])
    op.create_foreign_key('fk_storage_diff_block_number_blocks', 'storage_diff', 'blocks', ['block_number'], ['block_number'])
    op.drop_constraint(op.f('fk_storage_address_state'), 'storage', type_='foreignkey')
    op.create_foreign_key('fk_storage_address_state', 'storage', 'state', ['address'], ['address'])
    op.drop_constraint(op.f('fk_state_diff_transaction_hash_transactions'), 'state_diff', type_='foreignkey')
    op.drop_constraint(op.f('fk_state_diff_block_number_blocks'), 'state_diff', type_='foreignkey')
    op.create_foreign_key('fk_state_diff_transaction_hash_transactions', 'state_diff', 'transactions', ['transaction_hash'], ['transaction_hash'])
    op.create_foreign_key('fk_state_diff_block_number_blocks', 'state_diff', 'blocks', ['block_number'], ['block_number'])
    op.alter_column('state_diff', 'address',
               existing_type=sa.VARCHAR(length=42),
               nullable=True)
    op.drop_constraint(op.f('fk_receipts_block_number_blocks'), 'receipts', type_='foreignkey')
    op.drop_constraint(op.f('fk_receipts_transaction_hash_transactions'), 'receipts', type_='foreignkey')
    op.create_foreign_key('fk_receipts_block_number_blocks', 'receipts', 'blocks', ['block_number'], ['block_number'])
    op.create_foreign_key('fk_receipts_transaction_hash_transactions', 'receipts', 'transactions', ['transaction_hash'], ['transaction_hash'])
    op.drop_constraint(op.f('fk_meta_info_last_pushed_block_blocks'), 'meta_info', type_='foreignkey')
    op.create_foreign_key('fk_meta_info_last_pushed_block_blocks', 'meta_info', 'blocks', ['last_pushed_block'], ['block_number'])
    op.drop_constraint(op.f('fk_logs_block_number_blocks'), 'logs', type_='foreignkey')
    op.drop_constraint(op.f('fk_logs_transaction_hash_transactions'), 'logs', type_='foreignkey')
    op.create_foreign_key('fk_logs_block_number_blocks', 'logs', 'blocks', ['block_number'], ['block_number'])
    op.create_foreign_key('fk_logs_transaction_hash_transactions', 'logs', 'transactions', ['transaction_hash'], ['transaction_hash'])
    op.alter_column('logs', 'address',
               existing_type=sa.VARCHAR(length=42),
               nullable=True)
    op.drop_table('block_task_meta')
    # ### end Alembic commands ###
