"""empty message

Revision ID: 36f3ba12d5e5
Revises: None
Create Date: 2016-04-30 20:06:43.632886

"""

# revision identifiers, used by Alembic.
revision = '36f3ba12d5e5'
down_revision = None

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('images',
    sa.Column('id_', sa.Integer(), nullable=False),
    sa.Column('key', sa.Text(), nullable=False),
    sa.PrimaryKeyConstraint('id_', name=op.f('pk_images')),
    sa.UniqueConstraint('key', name=op.f('uq_images_key'))
    )
    op.create_table('locations',
    sa.Column('id_', sa.Integer(), nullable=False),
    sa.Column('latitude', sa.DECIMAL(), nullable=False),
    sa.Column('longitude', sa.DECIMAL(), nullable=False),
    sa.PrimaryKeyConstraint('id_', name=op.f('pk_locations'))
    )
    op.create_table('managers',
    sa.Column('id_', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.PrimaryKeyConstraint('id_', name=op.f('pk_managers')),
    sa.UniqueConstraint('user_id', name=op.f('uq_managers_user_id'))
    )
    op.create_table('branches',
    sa.Column('id_', sa.Integer(), nullable=False),
    sa.Column('title', sa.Text(), nullable=False),
    sa.Column('photo', sa.Text(), nullable=True),
    sa.Column('address', sa.Text(), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('location_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id_'], name=op.f('fk_branches_location_id_locations')),
    sa.PrimaryKeyConstraint('id_', name=op.f('pk_branches'))
    )
    op.create_table('category_images',
    sa.Column('image_id', sa.Integer(), nullable=False),
    sa.Column('category_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['category_id'], ['categories.id_'], name=op.f('fk_category_images_category_id_categories'), ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['image_id'], ['images.id_'], name=op.f('fk_category_images_image_id_images'), ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('image_id', 'category_id', name=op.f('pk_category_images'))
    )
    op.create_table('orders',
    sa.Column('id_', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('first_name', sa.Text(), nullable=False),
    sa.Column('last_name', sa.Text(), nullable=True),
    sa.Column('username', sa.Text(), nullable=True),
    sa.Column('manager_id', sa.Integer(), nullable=True),
    sa.Column('date', sa.DateTime(), nullable=False),
    sa.Column('phone_number', sa.Text(), nullable=True),
    sa.Column('address', sa.Text(), nullable=True),
    sa.Column('status', sa.Integer(), nullable=False),
    sa.Column('location_id', sa.Integer(), nullable=True),
    sa.Column('branch_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['branch_id'], ['branches.id_'], name=op.f('fk_orders_branch_id_branches')),
    sa.ForeignKeyConstraint(['location_id'], ['locations.id_'], name=op.f('fk_orders_location_id_locations')),
    sa.ForeignKeyConstraint(['manager_id'], ['managers.id_'], name=op.f('fk_orders_manager_id_managers')),
    sa.PrimaryKeyConstraint('id_', name=op.f('pk_orders'))
    )
    op.create_table('order_items',
    sa.Column('order_id', sa.Integer(), nullable=False),
    sa.Column('item_id', sa.Integer(), nullable=False),
    sa.Column('count', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['item_id'], ['items.id_'], name=op.f('fk_order_items_item_id_items'), ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['order_id'], ['orders.id_'], name=op.f('fk_order_items_order_id_orders'), ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('order_id', 'item_id', name=op.f('pk_order_items'))
    )
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('order_items')
    op.drop_table('orders')
    op.drop_table('category_images')
    op.drop_table('branches')
    op.drop_table('managers')
    op.drop_table('locations')
    op.drop_table('images')
    ### end Alembic commands ###
