"""delete dealer

Revision ID: 7f5a5ea86cf3
Revises: a2c6970d8137
Create Date: 2017-02-22 21:54:46.908764

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '7f5a5ea86cf3'
down_revision = 'a2c6970d8137'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('orders_dealer_id_fkey', 'orders', type_='foreignkey')
    op.drop_table('dealers')
    op.drop_table('districts')
    op.add_column('orders', sa.Column('user_id', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'orders', 'users', ['user_id'], ['id'])
    op.drop_column('orders', 'dealer_id')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('orders', sa.Column('dealer_id', sa.INTEGER(), autoincrement=False, nullable=True))
    op.drop_constraint(None, 'orders', type_='foreignkey')
    op.create_foreign_key('orders_dealer_id_fkey', 'orders', 'dealers', ['dealer_id'], ['id'])
    op.drop_column('orders', 'user_id')
    op.create_table('dealers',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('name', sa.VARCHAR(length=200), autoincrement=False, nullable=True),
    sa.Column('district_id', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['district_id'], ['districts.id'], name='dealers_district_id_fkey'),
    sa.PrimaryKeyConstraint('id', name='dealers_pkey')
    )
    op.create_table('districts',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('name', sa.VARCHAR(length=200), autoincrement=False, nullable=True),
    sa.Column('person_in_charge', sa.VARCHAR(length=200), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', name='districts_pkey')
    )
    # ### end Alembic commands ###
