"""empty message

Revision ID: a2aeb71e3351
Revises: 
Create Date: 2020-08-15 19:07:35.552634

"""
from alembic import op
import sqlalchemy as sa


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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('sys_department',
    sa.Column('id', sa.String(length=20), autoincrement=False, nullable=False, comment='主键ID'),
    sa.Column('state', sa.SmallInteger(), nullable=True, comment='状态值, 0为已删除, 1为正常, 2为锁定'),
    sa.Column('create_time', sa.DateTime(), nullable=False, comment='创建时间'),
    sa.Column('create_by_id', sa.BigInteger(), nullable=True, comment='创建者ID'),
    sa.Column('last_change_time', sa.DateTime(), nullable=True, comment='最后修改的时间'),
    sa.Column('change_by_id', sa.BigInteger(), nullable=True, comment='最后修改者ID'),
    sa.Column('deleted_time', sa.DateTime(), nullable=True, comment='删除时间'),
    sa.Column('deleted_by_id', sa.BigInteger(), nullable=True, comment='删除者id'),
    sa.Column('idx', sa.SmallInteger(), nullable=True, comment='显示排序'),
    sa.Column('department_name', sa.String(length=30), nullable=False, comment='部门名称'),
    sa.Column('department_code', sa.String(length=15), nullable=False, comment='部门编号'),
    sa.Column('remarks', sa.String(length=200), nullable=True, comment='备注说明'),
    sa.Column('parent_id', sa.String(length=20), nullable=True, comment='部门父级id'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id'),
    comment='后台部门表'
    )
    op.create_index(op.f('ix_sys_department_change_by_id'), 'sys_department', ['change_by_id'], unique=False)
    op.create_index(op.f('ix_sys_department_create_by_id'), 'sys_department', ['create_by_id'], unique=False)
    op.create_index(op.f('ix_sys_department_deleted_by_id'), 'sys_department', ['deleted_by_id'], unique=False)
    op.create_index(op.f('ix_sys_department_parent_id'), 'sys_department', ['parent_id'], unique=False)
    op.create_index(op.f('ix_sys_department_state'), 'sys_department', ['state'], unique=False)
    op.create_table('sys_login_log',
    sa.Column('id', sa.String(length=20), autoincrement=False, nullable=False, comment='主键ID'),
    sa.Column('state', sa.SmallInteger(), nullable=True, comment='状态值, 0为已删除, 1为正常, 2为锁定'),
    sa.Column('create_time', sa.DateTime(), nullable=False, comment='创建时间'),
    sa.Column('create_by_id', sa.BigInteger(), nullable=True, comment='创建者ID'),
    sa.Column('last_change_time', sa.DateTime(), nullable=True, comment='最后修改的时间'),
    sa.Column('change_by_id', sa.BigInteger(), nullable=True, comment='最后修改者ID'),
    sa.Column('deleted_time', sa.DateTime(), nullable=True, comment='删除时间'),
    sa.Column('deleted_by_id', sa.BigInteger(), nullable=True, comment='删除者id'),
    sa.Column('login_name', sa.String(length=30), nullable=True, comment='登陆账号'),
    sa.Column('user_name', sa.String(length=100), nullable=True, comment='用户名'),
    sa.Column('login_ip', sa.String(length=30), nullable=True, comment='操作ip'),
    sa.Column('browser', sa.String(length=300), nullable=True, comment='浏览器'),
    sa.Column('is_success', sa.Boolean(), nullable=True, comment='是否成功登陆'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id')
    )
    op.create_index(op.f('ix_sys_login_log_change_by_id'), 'sys_login_log', ['change_by_id'], unique=False)
    op.create_index(op.f('ix_sys_login_log_create_by_id'), 'sys_login_log', ['create_by_id'], unique=False)
    op.create_index(op.f('ix_sys_login_log_deleted_by_id'), 'sys_login_log', ['deleted_by_id'], unique=False)
    op.create_index(op.f('ix_sys_login_log_state'), 'sys_login_log', ['state'], unique=False)
    op.create_table('sys_menu',
    sa.Column('id', sa.String(length=20), autoincrement=False, nullable=False, comment='主键ID'),
    sa.Column('state', sa.SmallInteger(), nullable=True, comment='状态值, 0为已删除, 1为正常, 2为锁定'),
    sa.Column('create_time', sa.DateTime(), nullable=False, comment='创建时间'),
    sa.Column('create_by_id', sa.BigInteger(), nullable=True, comment='创建者ID'),
    sa.Column('last_change_time', sa.DateTime(), nullable=True, comment='最后修改的时间'),
    sa.Column('change_by_id', sa.BigInteger(), nullable=True, comment='最后修改者ID'),
    sa.Column('deleted_time', sa.DateTime(), nullable=True, comment='删除时间'),
    sa.Column('deleted_by_id', sa.BigInteger(), nullable=True, comment='删除者id'),
    sa.Column('idx', sa.SmallInteger(), nullable=True, comment='排序'),
    sa.Column('parent_id', sa.String(length=20), nullable=True, comment='父级菜单id'),
    sa.Column('menu_name', sa.String(length=30), nullable=False, comment='菜单名称'),
    sa.Column('menu_code', sa.String(length=100), nullable=False, comment='前端请求文件的路径里,@views后的路径或填Layout'),
    sa.Column('menu_url', sa.String(length=100), nullable=False, comment='菜单url,即访问后台接口的url'),
    sa.Column('menu_icon', sa.String(length=100), nullable=True, comment='图标，meta里面的icon'),
    sa.Column('menu_type', sa.SmallInteger(), nullable=True, comment='资源类型,1为菜单、2为按钮、3为动作'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id'),
    comment='菜单表'
    )
    op.create_index(op.f('ix_sys_menu_change_by_id'), 'sys_menu', ['change_by_id'], unique=False)
    op.create_index(op.f('ix_sys_menu_create_by_id'), 'sys_menu', ['create_by_id'], unique=False)
    op.create_index(op.f('ix_sys_menu_deleted_by_id'), 'sys_menu', ['deleted_by_id'], unique=False)
    op.create_index(op.f('ix_sys_menu_parent_id'), 'sys_menu', ['parent_id'], unique=False)
    op.create_index(op.f('ix_sys_menu_state'), 'sys_menu', ['state'], unique=False)
    op.create_table('sys_operation_log',
    sa.Column('id', sa.String(length=20), autoincrement=False, nullable=False, comment='主键ID'),
    sa.Column('state', sa.SmallInteger(), nullable=True, comment='状态值, 0为已删除, 1为正常, 2为锁定'),
    sa.Column('create_time', sa.DateTime(), nullable=False, comment='创建时间'),
    sa.Column('create_by_id', sa.BigInteger(), nullable=True, comment='创建者ID'),
    sa.Column('last_change_time', sa.DateTime(), nullable=True, comment='最后修改的时间'),
    sa.Column('change_by_id', sa.BigInteger(), nullable=True, comment='最后修改者ID'),
    sa.Column('deleted_time', sa.DateTime(), nullable=True, comment='删除时间'),
    sa.Column('deleted_by_id', sa.BigInteger(), nullable=True, comment='删除者id'),
    sa.Column('operation_url', sa.String(length=100), nullable=True, comment='操作链接'),
    sa.Column('ip', sa.String(length=300), nullable=True, comment='操作ip'),
    sa.Column('browser', sa.String(length=300), nullable=True, comment='浏览器'),
    sa.Column('login_name', sa.String(length=50), nullable=True, comment='操作用户'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id')
    )
    op.create_index(op.f('ix_sys_operation_log_change_by_id'), 'sys_operation_log', ['change_by_id'], unique=False)
    op.create_index(op.f('ix_sys_operation_log_create_by_id'), 'sys_operation_log', ['create_by_id'], unique=False)
    op.create_index(op.f('ix_sys_operation_log_deleted_by_id'), 'sys_operation_log', ['deleted_by_id'], unique=False)
    op.create_index(op.f('ix_sys_operation_log_state'), 'sys_operation_log', ['state'], unique=False)
    op.create_table('sys_role',
    sa.Column('id', sa.String(length=20), autoincrement=False, nullable=False, comment='主键ID'),
    sa.Column('state', sa.SmallInteger(), nullable=True, comment='状态值, 0为已删除, 1为正常, 2为锁定'),
    sa.Column('create_time', sa.DateTime(), nullable=False, comment='创建时间'),
    sa.Column('create_by_id', sa.BigInteger(), nullable=True, comment='创建者ID'),
    sa.Column('last_change_time', sa.DateTime(), nullable=True, comment='最后修改的时间'),
    sa.Column('change_by_id', sa.BigInteger(), nullable=True, comment='最后修改者ID'),
    sa.Column('deleted_time', sa.DateTime(), nullable=True, comment='删除时间'),
    sa.Column('deleted_by_id', sa.BigInteger(), nullable=True, comment='删除者id'),
    sa.Column('role_name', sa.String(length=30), nullable=False, comment='角色名称'),
    sa.Column('data_permission_type', sa.SmallInteger(), nullable=False, comment='数据权限(可以查看什么部门的数据),0仅自己参与过的数据,1本部门的权限, 2本部门及所有子部门权限，3表示全部权限,4自定义权限'),
    sa.Column('remarks', sa.String(length=200), nullable=True, comment='备注说明'),
    sa.Column('idx', sa.SmallInteger(), nullable=True, comment='显示排序'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id'),
    comment='后台角色表'
    )
    op.create_index(op.f('ix_sys_role_change_by_id'), 'sys_role', ['change_by_id'], unique=False)
    op.create_index(op.f('ix_sys_role_create_by_id'), 'sys_role', ['create_by_id'], unique=False)
    op.create_index(op.f('ix_sys_role_deleted_by_id'), 'sys_role', ['deleted_by_id'], unique=False)
    op.create_index(op.f('ix_sys_role_state'), 'sys_role', ['state'], unique=False)
    op.create_table('sys_role_data_permission',
    sa.Column('id', sa.String(length=20), autoincrement=False, nullable=False, comment='主键ID'),
    sa.Column('state', sa.SmallInteger(), nullable=True, comment='状态值, 0为已删除, 1为正常, 2为锁定'),
    sa.Column('create_time', sa.DateTime(), nullable=False, comment='创建时间'),
    sa.Column('create_by_id', sa.BigInteger(), nullable=True, comment='创建者ID'),
    sa.Column('last_change_time', sa.DateTime(), nullable=True, comment='最后修改的时间'),
    sa.Column('change_by_id', sa.BigInteger(), nullable=True, comment='最后修改者ID'),
    sa.Column('deleted_time', sa.DateTime(), nullable=True, comment='删除时间'),
    sa.Column('deleted_by_id', sa.BigInteger(), nullable=True, comment='删除者id'),
    sa.Column('role_id', sa.String(length=20), nullable=True, comment='角色id'),
    sa.Column('department_id', sa.String(length=20), nullable=True, comment='部门id'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id'),
    comment='角色数据权限表'
    )
    op.create_index(op.f('ix_sys_role_data_permission_change_by_id'), 'sys_role_data_permission', ['change_by_id'], unique=False)
    op.create_index(op.f('ix_sys_role_data_permission_create_by_id'), 'sys_role_data_permission', ['create_by_id'], unique=False)
    op.create_index(op.f('ix_sys_role_data_permission_deleted_by_id'), 'sys_role_data_permission', ['deleted_by_id'], unique=False)
    op.create_index(op.f('ix_sys_role_data_permission_department_id'), 'sys_role_data_permission', ['department_id'], unique=False)
    op.create_index(op.f('ix_sys_role_data_permission_role_id'), 'sys_role_data_permission', ['role_id'], unique=False)
    op.create_index(op.f('ix_sys_role_data_permission_state'), 'sys_role_data_permission', ['state'], unique=False)
    op.create_table('sys_role_menu_rel',
    sa.Column('id', sa.String(length=20), autoincrement=False, nullable=False, comment='主键ID'),
    sa.Column('state', sa.SmallInteger(), nullable=True, comment='状态值, 0为已删除, 1为正常, 2为锁定'),
    sa.Column('create_time', sa.DateTime(), nullable=False, comment='创建时间'),
    sa.Column('create_by_id', sa.BigInteger(), nullable=True, comment='创建者ID'),
    sa.Column('last_change_time', sa.DateTime(), nullable=True, comment='最后修改的时间'),
    sa.Column('change_by_id', sa.BigInteger(), nullable=True, comment='最后修改者ID'),
    sa.Column('deleted_time', sa.DateTime(), nullable=True, comment='删除时间'),
    sa.Column('deleted_by_id', sa.BigInteger(), nullable=True, comment='删除者id'),
    sa.Column('role_id', sa.String(length=20), nullable=True, comment='角色id'),
    sa.Column('menu_id', sa.String(length=20), nullable=True, comment='菜单id'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id'),
    comment='角色菜单表'
    )
    op.create_index(op.f('ix_sys_role_menu_rel_change_by_id'), 'sys_role_menu_rel', ['change_by_id'], unique=False)
    op.create_index(op.f('ix_sys_role_menu_rel_create_by_id'), 'sys_role_menu_rel', ['create_by_id'], unique=False)
    op.create_index(op.f('ix_sys_role_menu_rel_deleted_by_id'), 'sys_role_menu_rel', ['deleted_by_id'], unique=False)
    op.create_index(op.f('ix_sys_role_menu_rel_menu_id'), 'sys_role_menu_rel', ['menu_id'], unique=False)
    op.create_index(op.f('ix_sys_role_menu_rel_role_id'), 'sys_role_menu_rel', ['role_id'], unique=False)
    op.create_index(op.f('ix_sys_role_menu_rel_state'), 'sys_role_menu_rel', ['state'], unique=False)
    op.create_table('sys_user',
    sa.Column('id', sa.String(length=20), autoincrement=False, nullable=False, comment='主键ID'),
    sa.Column('state', sa.SmallInteger(), nullable=True, comment='状态值, 0为已删除, 1为正常, 2为锁定'),
    sa.Column('create_time', sa.DateTime(), nullable=False, comment='创建时间'),
    sa.Column('create_by_id', sa.BigInteger(), nullable=True, comment='创建者ID'),
    sa.Column('last_change_time', sa.DateTime(), nullable=True, comment='最后修改的时间'),
    sa.Column('change_by_id', sa.BigInteger(), nullable=True, comment='最后修改者ID'),
    sa.Column('deleted_time', sa.DateTime(), nullable=True, comment='删除时间'),
    sa.Column('deleted_by_id', sa.BigInteger(), nullable=True, comment='删除者id'),
    sa.Column('login_name', sa.String(length=30), nullable=False, comment='登录名'),
    sa.Column('password', sa.String(length=50), nullable=False, comment='密码'),
    sa.Column('user_name', sa.String(length=50), nullable=False, comment='用户名'),
    sa.Column('gender', sa.SmallInteger(), nullable=False, comment='性别，0为未知，1为男，2为女'),
    sa.Column('phone', sa.String(length=15), nullable=False, comment='手机号码'),
    sa.Column('wechat_no', sa.String(length=30), nullable=True, comment='微信号'),
    sa.Column('email', sa.String(length=30), nullable=True, comment='邮箱'),
    sa.Column('birthday', sa.Date(), nullable=True, comment='生日'),
    sa.Column('department_id', sa.String(length=20), nullable=True, comment='部门id'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id'),
    comment='后台用户表'
    )
    op.create_index(op.f('ix_sys_user_change_by_id'), 'sys_user', ['change_by_id'], unique=False)
    op.create_index(op.f('ix_sys_user_create_by_id'), 'sys_user', ['create_by_id'], unique=False)
    op.create_index(op.f('ix_sys_user_deleted_by_id'), 'sys_user', ['deleted_by_id'], unique=False)
    op.create_index(op.f('ix_sys_user_department_id'), 'sys_user', ['department_id'], unique=False)
    op.create_index(op.f('ix_sys_user_state'), 'sys_user', ['state'], unique=False)
    op.create_table('sys_user_role_rel',
    sa.Column('id', sa.String(length=20), autoincrement=False, nullable=False, comment='主键ID'),
    sa.Column('state', sa.SmallInteger(), nullable=True, comment='状态值, 0为已删除, 1为正常, 2为锁定'),
    sa.Column('create_time', sa.DateTime(), nullable=False, comment='创建时间'),
    sa.Column('create_by_id', sa.BigInteger(), nullable=True, comment='创建者ID'),
    sa.Column('last_change_time', sa.DateTime(), nullable=True, comment='最后修改的时间'),
    sa.Column('change_by_id', sa.BigInteger(), nullable=True, comment='最后修改者ID'),
    sa.Column('deleted_time', sa.DateTime(), nullable=True, comment='删除时间'),
    sa.Column('deleted_by_id', sa.BigInteger(), nullable=True, comment='删除者id'),
    sa.Column('user_id', sa.String(length=20), nullable=True, comment='用户id'),
    sa.Column('role_id', sa.String(length=20), nullable=True, comment='角色id'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id'),
    comment='用户角色表'
    )
    op.create_index(op.f('ix_sys_user_role_rel_change_by_id'), 'sys_user_role_rel', ['change_by_id'], unique=False)
    op.create_index(op.f('ix_sys_user_role_rel_create_by_id'), 'sys_user_role_rel', ['create_by_id'], unique=False)
    op.create_index(op.f('ix_sys_user_role_rel_deleted_by_id'), 'sys_user_role_rel', ['deleted_by_id'], unique=False)
    op.create_index(op.f('ix_sys_user_role_rel_role_id'), 'sys_user_role_rel', ['role_id'], unique=False)
    op.create_index(op.f('ix_sys_user_role_rel_state'), 'sys_user_role_rel', ['state'], unique=False)
    op.create_index(op.f('ix_sys_user_role_rel_user_id'), 'sys_user_role_rel', ['user_id'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_sys_user_role_rel_user_id'), table_name='sys_user_role_rel')
    op.drop_index(op.f('ix_sys_user_role_rel_state'), table_name='sys_user_role_rel')
    op.drop_index(op.f('ix_sys_user_role_rel_role_id'), table_name='sys_user_role_rel')
    op.drop_index(op.f('ix_sys_user_role_rel_deleted_by_id'), table_name='sys_user_role_rel')
    op.drop_index(op.f('ix_sys_user_role_rel_create_by_id'), table_name='sys_user_role_rel')
    op.drop_index(op.f('ix_sys_user_role_rel_change_by_id'), table_name='sys_user_role_rel')
    op.drop_table('sys_user_role_rel')
    op.drop_index(op.f('ix_sys_user_state'), table_name='sys_user')
    op.drop_index(op.f('ix_sys_user_department_id'), table_name='sys_user')
    op.drop_index(op.f('ix_sys_user_deleted_by_id'), table_name='sys_user')
    op.drop_index(op.f('ix_sys_user_create_by_id'), table_name='sys_user')
    op.drop_index(op.f('ix_sys_user_change_by_id'), table_name='sys_user')
    op.drop_table('sys_user')
    op.drop_index(op.f('ix_sys_role_menu_rel_state'), table_name='sys_role_menu_rel')
    op.drop_index(op.f('ix_sys_role_menu_rel_role_id'), table_name='sys_role_menu_rel')
    op.drop_index(op.f('ix_sys_role_menu_rel_menu_id'), table_name='sys_role_menu_rel')
    op.drop_index(op.f('ix_sys_role_menu_rel_deleted_by_id'), table_name='sys_role_menu_rel')
    op.drop_index(op.f('ix_sys_role_menu_rel_create_by_id'), table_name='sys_role_menu_rel')
    op.drop_index(op.f('ix_sys_role_menu_rel_change_by_id'), table_name='sys_role_menu_rel')
    op.drop_table('sys_role_menu_rel')
    op.drop_index(op.f('ix_sys_role_data_permission_state'), table_name='sys_role_data_permission')
    op.drop_index(op.f('ix_sys_role_data_permission_role_id'), table_name='sys_role_data_permission')
    op.drop_index(op.f('ix_sys_role_data_permission_department_id'), table_name='sys_role_data_permission')
    op.drop_index(op.f('ix_sys_role_data_permission_deleted_by_id'), table_name='sys_role_data_permission')
    op.drop_index(op.f('ix_sys_role_data_permission_create_by_id'), table_name='sys_role_data_permission')
    op.drop_index(op.f('ix_sys_role_data_permission_change_by_id'), table_name='sys_role_data_permission')
    op.drop_table('sys_role_data_permission')
    op.drop_index(op.f('ix_sys_role_state'), table_name='sys_role')
    op.drop_index(op.f('ix_sys_role_deleted_by_id'), table_name='sys_role')
    op.drop_index(op.f('ix_sys_role_create_by_id'), table_name='sys_role')
    op.drop_index(op.f('ix_sys_role_change_by_id'), table_name='sys_role')
    op.drop_table('sys_role')
    op.drop_index(op.f('ix_sys_operation_log_state'), table_name='sys_operation_log')
    op.drop_index(op.f('ix_sys_operation_log_deleted_by_id'), table_name='sys_operation_log')
    op.drop_index(op.f('ix_sys_operation_log_create_by_id'), table_name='sys_operation_log')
    op.drop_index(op.f('ix_sys_operation_log_change_by_id'), table_name='sys_operation_log')
    op.drop_table('sys_operation_log')
    op.drop_index(op.f('ix_sys_menu_state'), table_name='sys_menu')
    op.drop_index(op.f('ix_sys_menu_parent_id'), table_name='sys_menu')
    op.drop_index(op.f('ix_sys_menu_deleted_by_id'), table_name='sys_menu')
    op.drop_index(op.f('ix_sys_menu_create_by_id'), table_name='sys_menu')
    op.drop_index(op.f('ix_sys_menu_change_by_id'), table_name='sys_menu')
    op.drop_table('sys_menu')
    op.drop_index(op.f('ix_sys_login_log_state'), table_name='sys_login_log')
    op.drop_index(op.f('ix_sys_login_log_deleted_by_id'), table_name='sys_login_log')
    op.drop_index(op.f('ix_sys_login_log_create_by_id'), table_name='sys_login_log')
    op.drop_index(op.f('ix_sys_login_log_change_by_id'), table_name='sys_login_log')
    op.drop_table('sys_login_log')
    op.drop_index(op.f('ix_sys_department_state'), table_name='sys_department')
    op.drop_index(op.f('ix_sys_department_parent_id'), table_name='sys_department')
    op.drop_index(op.f('ix_sys_department_deleted_by_id'), table_name='sys_department')
    op.drop_index(op.f('ix_sys_department_create_by_id'), table_name='sys_department')
    op.drop_index(op.f('ix_sys_department_change_by_id'), table_name='sys_department')
    op.drop_table('sys_department')
    # ### end Alembic commands ###
