"""v1_create_tables

Revision ID: ca3d7baa59cb
Revises: 
Create Date: 2018-01-21 16:03:21.558731

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'ca3d7baa59cb'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('tb_category',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('name', sa.VARCHAR(length=20), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('tb_user',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('name', sa.VARCHAR(length=20), nullable=False),
    sa.Column('password', sa.String(length=128), nullable=False),
    sa.Column('gender', sa.CHAR(length=1), nullable=True),
    sa.Column('birth', sa.DATE(), nullable=True),
    sa.Column('nickname', sa.VARCHAR(length=20), nullable=True),
    sa.Column('avatar', sa.VARCHAR(length=300), nullable=True),
    sa.Column('introduce', sa.VARCHAR(length=100), nullable=True),
    sa.Column('email', sa.VARCHAR(length=50), nullable=True),
    sa.Column('phone', sa.VARCHAR(length=11), nullable=True),
    sa.Column('register_datetime', sa.DATETIME(), server_default=sa.text('now()'), nullable=False),
    sa.Column('login_count', sa.INTEGER(), server_default='0', nullable=False),
    sa.Column('last_login_datetime', sa.DATETIME(), nullable=True),
    sa.Column('bonus', sa.INTEGER(), server_default='100', nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_tb_user_name'), 'tb_user', ['name'], unique=False)
    op.create_index(op.f('ix_tb_user_nickname'), 'tb_user', ['nickname'], unique=False)
    op.create_table('tb_link',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('name', sa.VARCHAR(length=20), nullable=False),
    sa.Column('link', sa.VARCHAR(length=300), nullable=False),
    sa.Column('user_id', sa.INTEGER(), nullable=True),
    sa.Column('category_id', sa.INTEGER(), nullable=True),
    sa.Column('add_datetime', sa.DATETIME(), server_default=sa.text('now()'), nullable=False),
    sa.Column('update_datetime', sa.DATETIME(), server_default=sa.text('now()'), nullable=False),
    sa.Column('description', sa.VARCHAR(length=100), nullable=True),
    sa.Column('link_check_state', sa.SMALLINT(), server_default='0', nullable=False),
    sa.Column('complaints_count', sa.INTEGER(), server_default='0', nullable=False),
    sa.Column('visit_count', sa.INTEGER(), server_default='0', nullable=False),
    sa.ForeignKeyConstraint(['category_id'], ['tb_category.id'], onupdate='CASCADE', ondelete='SET NULL'),
    sa.ForeignKeyConstraint(['user_id'], ['tb_user.id'], onupdate='CASCADE', ondelete='SET NULL'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_tb_link_add_datetime'), 'tb_link', ['add_datetime'], unique=False)
    op.create_index(op.f('ix_tb_link_category_id'), 'tb_link', ['category_id'], unique=False)
    op.create_index(op.f('ix_tb_link_complaints_count'), 'tb_link', ['complaints_count'], unique=False)
    op.create_index(op.f('ix_tb_link_description'), 'tb_link', ['description'], unique=False)
    op.create_index(op.f('ix_tb_link_link_check_state'), 'tb_link', ['link_check_state'], unique=False)
    op.create_index(op.f('ix_tb_link_name'), 'tb_link', ['name'], unique=False)
    op.create_index(op.f('ix_tb_link_update_datetime'), 'tb_link', ['update_datetime'], unique=False)
    op.create_index(op.f('ix_tb_link_user_id'), 'tb_link', ['user_id'], unique=False)
    op.create_index(op.f('ix_tb_link_visit_count'), 'tb_link', ['visit_count'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_tb_link_visit_count'), table_name='tb_link')
    op.drop_index(op.f('ix_tb_link_user_id'), table_name='tb_link')
    op.drop_index(op.f('ix_tb_link_update_datetime'), table_name='tb_link')
    op.drop_index(op.f('ix_tb_link_name'), table_name='tb_link')
    op.drop_index(op.f('ix_tb_link_link_check_state'), table_name='tb_link')
    op.drop_index(op.f('ix_tb_link_description'), table_name='tb_link')
    op.drop_index(op.f('ix_tb_link_complaints_count'), table_name='tb_link')
    op.drop_index(op.f('ix_tb_link_category_id'), table_name='tb_link')
    op.drop_index(op.f('ix_tb_link_add_datetime'), table_name='tb_link')
    op.drop_table('tb_link')
    op.drop_index(op.f('ix_tb_user_nickname'), table_name='tb_user')
    op.drop_index(op.f('ix_tb_user_name'), table_name='tb_user')
    op.drop_table('tb_user')
    op.drop_table('tb_category')
    # ### end Alembic commands ###
