"""Initial migration

Revision ID: 2c7cc7d09efe
Revises: None
Create Date: 2019-03-18 17:00:23.187262

"""

# revision identifiers, used by Alembic.
revision = '2c7cc7d09efe'
down_revision = None

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('exchange_volume',
    sa.Column('exchange_volume_id', sa.Integer(), nullable=False),
    sa.Column('unique_id', sa.Unicode(length=64), nullable=False),
    sa.Column('exchange', sa.Unicode(length=64), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.Column('time_created', sa.DateTime(), nullable=False),
    sa.Column('exchange_volume', sa.Numeric(precision=20, scale=10), nullable=True),
    sa.PrimaryKeyConstraint('exchange_volume_id')
    )
    op.create_table('orderbook',
    sa.Column('orderbook_id', sa.Integer(), nullable=False),
    sa.Column('unique_id', sa.Unicode(length=64), nullable=False),
    sa.Column('exchange', sa.Unicode(length=64), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('time_created', sa.DateTime(), nullable=False),
    sa.Column('bids', sa.UnicodeText(length=2147483648), nullable=True),
    sa.Column('asks', sa.UnicodeText(length=2147483648), nullable=True),
    sa.PrimaryKeyConstraint('orderbook_id')
    )
    op.create_table('trade',
    sa.Column('trade_id', sa.Integer(), nullable=False),
    sa.Column('unique_id', sa.Unicode(length=64), nullable=False),
    sa.Column('exchange', sa.Unicode(length=64), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.Column('time_created', sa.DateTime(), nullable=False),
    sa.Column('exchange_trade_id', sa.Unicode(length=64), nullable=True),
    sa.Column('source', sa.Unicode(length=64), nullable=False),
    sa.Column('price', sa.Numeric(precision=20, scale=10), nullable=True),
    sa.Column('price_currency', sa.Unicode(length=3), nullable=True),
    sa.Column('volume', sa.Numeric(precision=20, scale=10), nullable=True),
    sa.Column('volume_currency', sa.Unicode(length=3), nullable=True),
    sa.PrimaryKeyConstraint('trade_id'),
    sa.UniqueConstraint('exchange','exchange_trade_id', name='uniq_exchange_exchange_trade_id')
    )

    op.create_index('idx_timestamp_exchange', 'exchange_volume', ['timestamp', 'exchange'])

    op.create_index('idx_timestamp_exchange', 'orderbook', ['timestamp', 'exchange'])
    op.create_index('idx_timestamp_exchange', 'trade', ['timestamp', 'exchange'])
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('trade')
    op.drop_table('orderbook')
    op.drop_table('exchange_volume')
    ### end Alembic commands ###
