"""add current state tables

Revision ID: efc3b5068a72
Revises: ef91a56cb621
Create Date: 2018-06-19 13:45:26.712382

"""
from alembic import op
import sqlalchemy as sa


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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('state',
    sa.Column('address', sa.String(length=42), nullable=False),
    sa.Column('balance', sa.Numeric(), nullable=False),
    sa.Column('nonce', sa.Integer(), nullable=True),
    sa.Column('code', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('address')
    )
    op.create_index(op.f('ix_state_address'), 'state', ['address'], unique=False)
    op.create_table('storage',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('address', sa.String(length=42), nullable=True),
    sa.Column('position', sa.String(length=66), nullable=False),
    sa.Column('storage', sa.String(length=66), nullable=False),
    sa.ForeignKeyConstraint(['address'], ['state.address'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_storage_position'), 'storage', ['position'], unique=False)
    op.add_column('meta_info', sa.Column('current_state_block', sa.Numeric(), nullable=True))
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('meta_info', 'current_state_block')
    op.drop_index(op.f('ix_storage_position'), table_name='storage')
    op.drop_table('storage')
    op.drop_index(op.f('ix_state_address'), table_name='state')
    op.drop_table('state')
    # ### end Alembic commands ###
