"""Add column quantity in trades

Revision ID: 55199046e99a
Revises: c39e3caf08b6
Create Date: 2021-04-14 16:57:44.518021

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '55199046e99a'
down_revision = 'c39e3caf08b6'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('orders', sa.Column('trade_id', sa.Integer(), nullable=False))
    op.create_foreign_key(
        constraint_name='orders_trade_id_fkey',
        source_table='orders',
        referent_table='trades',
        local_cols=['trade_id'],
        remote_cols=['trade_id'])
    op.add_column('trades', sa.Column('quantity', sa.Numeric(), nullable=True))
    op.alter_column('trades', 'stop_loss',
               existing_type=sa.NUMERIC(),
               nullable=True)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('trades', 'stop_loss',
               existing_type=sa.NUMERIC(),
               nullable=False)
    op.drop_column('trades', 'quantity')
    op.drop_constraint(constraint_name='orders_trade_id_fkey', table_name='orders', type_='foreignkey')
    op.drop_column('orders', 'trade_id')
    # ### end Alembic commands ###
