"""first change

Revision ID: 10f48d555d4a
Revises: 
Create Date: 2018-05-30 15:08:22.413840

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '10f48d555d4a'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('blocks',
    sa.Column('block_number', sa.Numeric(), nullable=False),
    sa.Column('block_hash', sa.String(length=66), nullable=False),
    sa.Column('parent_hash', sa.String(length=66), nullable=False),
    sa.Column('difficulty', sa.Numeric(), nullable=False),
    sa.Column('gas_used', sa.Numeric(), nullable=False),
    sa.Column('miner', sa.String(length=42), nullable=False),
    sa.Column('timestamp', sa.TIMESTAMP(), nullable=False),
    sa.Column('sha3uncles', sa.String(length=66), nullable=False),
    sa.Column('extra_data', sa.Text(), nullable=True),
    sa.Column('gas_limit', sa.Numeric(), nullable=False),
    sa.Column('uncle_count', sa.Numeric(), nullable=False),
    sa.Column('transaction_count', sa.Numeric(), nullable=False),
    sa.PrimaryKeyConstraint('block_number'),
    sa.UniqueConstraint('block_hash'),
    sa.UniqueConstraint('parent_hash'),
    sa.UniqueConstraint('timestamp')
    )
    op.create_index(op.f('ix_blocks_block_number'), 'blocks', ['block_number'], unique=False)
    op.create_table('transactions',
    sa.Column('transaction_hash', sa.String(length=66), nullable=False),
    sa.Column('block_number', sa.Numeric(), nullable=True),
    sa.Column('nonce', sa.Numeric(), nullable=False),
    sa.Column('sender', sa.String(length=42), nullable=False),
    sa.Column('receiver', sa.String(length=42), nullable=True),
    sa.Column('start_gas', sa.Numeric(), nullable=False),
    sa.Column('value', sa.Numeric(), nullable=True),
    sa.Column('data', sa.Text(), nullable=True),
    sa.Column('gas_price', sa.Numeric(), nullable=False),
    sa.Column('timestamp', sa.TIMESTAMP(), nullable=True),
    sa.Column('transaction_index', sa.Numeric(), nullable=False),
    sa.ForeignKeyConstraint(['block_number'], ['blocks.block_number'], ),
    sa.PrimaryKeyConstraint('transaction_hash')
    )
    op.create_index(op.f('ix_transactions_transaction_hash'), 'transactions', ['transaction_hash'], unique=False)
    op.create_table('uncles',
    sa.Column('uncle_hash', sa.String(length=66), nullable=False),
    sa.Column('uncle_blocknumber', sa.Numeric(), nullable=False),
    sa.Column('parent_hash', sa.String(length=66), nullable=False),
    sa.Column('difficulty', sa.String(length=66), nullable=False),
    sa.Column('current_blocknumber', sa.Numeric(), nullable=True),
    sa.Column('gas_used', sa.Numeric(), nullable=False),
    sa.Column('miner', sa.String(length=42), nullable=False),
    sa.Column('timestamp', sa.TIMESTAMP(), nullable=True),
    sa.Column('sha3uncles', sa.String(length=66), nullable=False),
    sa.Column('extra_data', sa.Text(), nullable=True),
    sa.Column('gas_limit', sa.Numeric(), nullable=False),
    sa.ForeignKeyConstraint(['current_blocknumber'], ['blocks.block_number'], ),
    sa.PrimaryKeyConstraint('uncle_hash')
    )
    op.create_index(op.f('ix_uncles_uncle_hash'), 'uncles', ['uncle_hash'], unique=True)
    op.create_table('logs',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('transaction_hash', sa.String(length=66), nullable=True),
    sa.Column('address', sa.String(length=42), nullable=True),
    sa.Column('data', sa.Text(), nullable=True),
    sa.Column('block_number', sa.Numeric(), nullable=True),
    sa.Column('timestamp', sa.TIMESTAMP(), nullable=True),
    sa.Column('transaction_index', sa.Numeric(), nullable=False),
    sa.Column('log_index', sa.Numeric(), nullable=False),
    sa.Column('topics_count', sa.Numeric(), nullable=False),
    sa.Column('topic_1', sa.String(length=66), nullable=True),
    sa.Column('topic_2', sa.String(length=66), nullable=True),
    sa.Column('topic_3', sa.String(length=66), nullable=True),
    sa.Column('topic_4', sa.String(length=66), nullable=True),
    sa.ForeignKeyConstraint(['block_number'], ['blocks.block_number'], ),
    sa.ForeignKeyConstraint(['transaction_hash'], ['transactions.transaction_hash'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_logs_transaction_hash'), 'logs', ['transaction_hash'], unique=False)
    op.create_table('receipts',
    sa.Column('transaction_hash', sa.String(length=66), nullable=False),
    sa.Column('status', sa.Boolean(), nullable=True),
    sa.Column('gas_used', sa.Numeric(), nullable=False),
    sa.Column('cumulative_gas_used', sa.Numeric(), nullable=False),
    sa.Column('contract_address', sa.String(length=42), nullable=True),
    sa.Column('block_number', sa.Numeric(), nullable=True),
    sa.Column('timestamp', sa.TIMESTAMP(), nullable=True),
    sa.Column('transaction_index', sa.Numeric(), nullable=False),
    sa.ForeignKeyConstraint(['block_number'], ['blocks.block_number'], ),
    sa.ForeignKeyConstraint(['transaction_hash'], ['transactions.transaction_hash'], ),
    sa.PrimaryKeyConstraint('transaction_hash')
    )
    op.create_index(op.f('ix_receipts_transaction_hash'), 'receipts', ['transaction_hash'], unique=False)
    op.create_table('traces',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('block_number', sa.Numeric(), nullable=True),
    sa.Column('transaction_hash', sa.String(length=66), nullable=True),
    sa.Column('trace_type', sa.String(), nullable=False),
    sa.Column('trace_address', sa.String(), nullable=False),
    sa.Column('subtraces', sa.Numeric(), nullable=True),
    sa.Column('transaction_index', sa.Numeric(), nullable=True),
    sa.Column('sender', sa.String(length=42), nullable=True),
    sa.Column('receiver', sa.String(length=42), nullable=True),
    sa.Column('value', sa.Numeric(), nullable=True),
    sa.Column('start_gas', sa.Numeric(), nullable=True),
    sa.Column('input_data', sa.Text(), nullable=True),
    sa.Column('gas_used', sa.Numeric(), nullable=True),
    sa.Column('contract_address', sa.String(length=42), nullable=True),
    sa.Column('output', sa.Text(), nullable=True),
    sa.Column('error', sa.String(length=42), nullable=True),
    sa.ForeignKeyConstraint(['block_number'], ['blocks.block_number'], ),
    sa.ForeignKeyConstraint(['transaction_hash'], ['transactions.transaction_hash'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_traces_transaction_hash'), 'traces', ['transaction_hash'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_traces_transaction_hash'), table_name='traces')
    op.drop_table('traces')
    op.drop_index(op.f('ix_receipts_transaction_hash'), table_name='receipts')
    op.drop_table('receipts')
    op.drop_index(op.f('ix_logs_transaction_hash'), table_name='logs')
    op.drop_table('logs')
    op.drop_index(op.f('ix_uncles_uncle_hash'), table_name='uncles')
    op.drop_table('uncles')
    op.drop_index(op.f('ix_transactions_transaction_hash'), table_name='transactions')
    op.drop_table('transactions')
    op.drop_index(op.f('ix_blocks_block_number'), table_name='blocks')
    op.drop_table('blocks')
    # ### end Alembic commands ###
