"""Add Category model

Revision ID: a80cb2a131ca
Revises: 59a4c44d8f6c
Create Date: 2020-02-07 08:26:22.689176

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'a80cb2a131ca'
down_revision = '59a4c44d8f6c'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('category',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(), nullable=True),
    sa.Column('lft', sa.Integer(), nullable=False),
    sa.Column('rgt', sa.Integer(), nullable=False),
    sa.Column('level', sa.Integer(), nullable=False),
    sa.Column('tree_id', sa.Integer(), nullable=True),
    sa.Column('parent_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['parent_id'], ['category.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('category_level_idx', 'category', ['level'], unique=False)
    op.create_index('category_lft_idx', 'category', ['lft'], unique=False)
    op.create_index('category_rgt_idx', 'category', ['rgt'], unique=False)
    op.create_index(op.f('ix_category_id'), 'category', ['id'], unique=False)
    op.create_index(op.f('ix_category_name'), 'category', ['name'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_category_name'), table_name='category')
    op.drop_index(op.f('ix_category_id'), table_name='category')
    op.drop_index('category_rgt_idx', table_name='category')
    op.drop_index('category_lft_idx', table_name='category')
    op.drop_index('category_level_idx', table_name='category')
    op.drop_table('category')
    # ### end Alembic commands ###
