"""framework initial schema Revision ID: 7de264f96a03 Revises: Create Date: 2026-05-08 04:33:59.055459 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = '7de264f96a03' down_revision = None branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('sys_config', sa.Column('type', sa.String(length=64), nullable=False, comment='配置类型'), sa.Column('name', sa.String(length=255), nullable=False, comment='配置名称'), sa.Column('code', sa.String(length=128), nullable=False, comment='配置编码'), sa.Column('value', sa.Text(), nullable=True, comment='配置值'), sa.Column('desc', sa.Text(), nullable=True, comment='配置描述'), sa.Column('sort', sa.Integer(), nullable=False, comment='排序'), sa.Column('status', sa.Enum('enabled', 'disabled', name='statusenum'), nullable=False, comment='状态'), sa.Column('id', sa.String(length=36), nullable=False, comment='标识'), sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'), sa.Column('created_by', sa.String(length=36), nullable=True, comment='创建人'), sa.Column('updated_at', sa.DateTime(), nullable=False, comment='更新时间'), sa.Column('updated_by', sa.String(length=36), nullable=True, comment='更新人'), sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'), sa.PrimaryKeyConstraint('id', name=op.f('pk_sys_config')), mysql_charset='utf8mb4', mysql_collate='utf8mb4_general_ci' ) with op.batch_alter_table('sys_config', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_sys_config_created_by'), ['created_by'], unique=False) batch_op.create_index(batch_op.f('ix_sys_config_updated_by'), ['updated_by'], unique=False) op.create_table('sys_dept', sa.Column('id', sa.String(length=36), nullable=False, comment='标识'), sa.Column('name', sa.String(length=255), nullable=False, comment='部门名称'), sa.Column('parent_id', sa.String(length=36), nullable=True, comment='父部门ID'), sa.Column('desc', sa.Text(), nullable=True, comment='部门描述'), sa.Column('sort', sa.Integer(), nullable=False, comment='排序'), sa.Column('leader_id', sa.String(length=36), nullable=True, comment='负责人ID'), sa.Column('status', sa.Enum('enabled', 'disabled', name='statusenum'), nullable=False, comment='状态'), sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'), sa.Column('updated_at', sa.DateTime(), nullable=False, comment='更新时间'), sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'), sa.PrimaryKeyConstraint('id', name=op.f('pk_sys_dept')), mysql_charset='utf8mb4', mysql_collate='utf8mb4_general_ci' ) op.create_table('sys_dict_data', sa.Column('type_code', sa.String(length=36), nullable=False, comment='类型编码'), sa.Column('label', sa.String(length=255), nullable=False, comment='数据标签'), sa.Column('code', sa.String(length=128), nullable=False, comment='数据编码'), sa.Column('value', sa.Text(), nullable=True, comment='数据值'), sa.Column('desc', sa.Text(), nullable=True, comment='数据描述'), sa.Column('sort', sa.Integer(), nullable=False, comment='排序'), sa.Column('status', sa.Enum('enabled', 'disabled', name='statusenum'), nullable=False, comment='状态'), sa.Column('id', sa.String(length=36), nullable=False, comment='标识'), sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'), sa.Column('created_by', sa.String(length=36), nullable=True, comment='创建人'), sa.Column('updated_at', sa.DateTime(), nullable=False, comment='更新时间'), sa.Column('updated_by', sa.String(length=36), nullable=True, comment='更新人'), sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'), sa.PrimaryKeyConstraint('id', name=op.f('pk_sys_dict_data')), mysql_charset='utf8mb4', mysql_collate='utf8mb4_general_ci' ) with op.batch_alter_table('sys_dict_data', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_sys_dict_data_created_by'), ['created_by'], unique=False) batch_op.create_index(batch_op.f('ix_sys_dict_data_updated_by'), ['updated_by'], unique=False) op.create_table('sys_dict_type', sa.Column('type_name', sa.String(length=255), nullable=False, comment='类型名称'), sa.Column('type_code', sa.String(length=128), nullable=False, comment='类型编码'), sa.Column('desc', sa.Text(), nullable=True, comment='类型描述'), sa.Column('sort', sa.Integer(), nullable=False, comment='排序'), sa.Column('status', sa.Enum('enabled', 'disabled', name='statusenum'), nullable=False, comment='状态'), sa.Column('id', sa.String(length=36), nullable=False, comment='标识'), sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'), sa.Column('created_by', sa.String(length=36), nullable=True, comment='创建人'), sa.Column('updated_at', sa.DateTime(), nullable=False, comment='更新时间'), sa.Column('updated_by', sa.String(length=36), nullable=True, comment='更新人'), sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'), sa.PrimaryKeyConstraint('id', name=op.f('pk_sys_dict_type')), sa.UniqueConstraint('type_code', name=op.f('uq_sys_dict_type_type_code')), mysql_charset='utf8mb4', mysql_collate='utf8mb4_general_ci' ) with op.batch_alter_table('sys_dict_type', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_sys_dict_type_created_by'), ['created_by'], unique=False) batch_op.create_index(batch_op.f('ix_sys_dict_type_updated_by'), ['updated_by'], unique=False) op.create_table('sys_file', sa.Column('filename', sa.String(length=255), nullable=False, comment='原始文件名'), sa.Column('file_key', sa.String(length=512), nullable=False, comment='存储路径'), sa.Column('file_hash', sa.String(length=64), nullable=True, comment='文件哈希'), sa.Column('mime_type', sa.String(length=128), nullable=True, comment='MIME类型'), sa.Column('file_size', sa.BigInteger(), nullable=False, comment='文件大小(字节)'), sa.Column('extension', sa.String(length=32), nullable=True, comment='文件扩展名'), sa.Column('storage_type', sa.Enum('local', 'aliyun_oss', 'tencent_cos', 'qiniu_kodo', 'huawei_obs', 'aws_s3', 'minio', name='storagetypeenum'), nullable=False, comment='存储类型'), sa.Column('storage_info', sa.JSON(), nullable=True, comment='存储信息(bucket/region/endpoint/meta等)'), sa.Column('directory_id', sa.String(length=36), nullable=True, comment='所属目录ID'), sa.Column('metadata', sa.JSON(), nullable=True, comment='扩展元数据'), sa.Column('is_deleted', sa.Boolean(), nullable=False, comment='是否已删除(回收站)'), sa.Column('deleted_at', sa.DateTime(), nullable=True, comment='删除时间'), sa.Column('deleted_by', sa.String(length=36), nullable=True, comment='删除人ID'), sa.Column('share_code', sa.String(length=64), nullable=True, comment='分享码'), sa.Column('share_password', sa.String(length=64), nullable=True, comment='分享密码'), sa.Column('share_expire_at', sa.DateTime(), nullable=True, comment='分享过期时间'), sa.Column('share_count', sa.Integer(), nullable=False, comment='分享访问次数'), sa.Column('status', sa.Enum('enabled', 'disabled', name='statusenum'), nullable=False, comment='状态'), sa.Column('id', sa.String(length=36), nullable=False, comment='标识'), sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'), sa.Column('created_by', sa.String(length=36), nullable=True, comment='创建人'), sa.Column('updated_at', sa.DateTime(), nullable=False, comment='更新时间'), sa.Column('updated_by', sa.String(length=36), nullable=True, comment='更新人'), sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'), sa.PrimaryKeyConstraint('id', name=op.f('pk_sys_file')), mysql_charset='utf8mb4', mysql_collate='utf8mb4_general_ci' ) with op.batch_alter_table('sys_file', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_sys_file_created_by'), ['created_by'], unique=False) batch_op.create_index(batch_op.f('ix_sys_file_directory_id'), ['directory_id'], unique=False) batch_op.create_index(batch_op.f('ix_sys_file_file_hash'), ['file_hash'], unique=False) batch_op.create_index(batch_op.f('ix_sys_file_file_key'), ['file_key'], unique=True) batch_op.create_index(batch_op.f('ix_sys_file_share_code'), ['share_code'], unique=True) batch_op.create_index(batch_op.f('ix_sys_file_updated_by'), ['updated_by'], unique=False) op.create_table('sys_file_directory', sa.Column('name', sa.String(length=255), nullable=False, comment='目录名称'), sa.Column('path', sa.String(length=1024), nullable=False, comment='完整路径'), sa.Column('parent_id', sa.String(length=36), nullable=True, comment='父目录ID'), sa.Column('level', sa.Integer(), nullable=True, comment='层级'), sa.Column('sort', sa.Integer(), nullable=True, comment='排序'), sa.Column('icon', sa.String(length=128), nullable=True, comment='目录图标'), sa.Column('color', sa.String(length=32), nullable=True, comment='颜色标记'), sa.Column('description', sa.Text(), nullable=True, comment='目录描述'), sa.Column('status', sa.Enum('enabled', 'disabled', name='statusenum'), nullable=False, comment='状态'), sa.Column('id', sa.String(length=36), nullable=False, comment='标识'), sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'), sa.Column('created_by', sa.String(length=36), nullable=True, comment='创建人'), sa.Column('updated_at', sa.DateTime(), nullable=False, comment='更新时间'), sa.Column('updated_by', sa.String(length=36), nullable=True, comment='更新人'), sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'), sa.PrimaryKeyConstraint('id', name=op.f('pk_sys_file_directory')) ) with op.batch_alter_table('sys_file_directory', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_sys_file_directory_created_by'), ['created_by'], unique=False) batch_op.create_index('ix_sys_file_directory_path', ['path'], unique=False, mysql_length=255) batch_op.create_index(batch_op.f('ix_sys_file_directory_updated_by'), ['updated_by'], unique=False) op.create_table('sys_log', sa.Column('name', sa.String(length=100), nullable=True, comment='操作名称'), sa.Column('method', sa.String(length=10), nullable=True, comment='请求方法'), sa.Column('user_id', sa.String(length=36), nullable=True, comment='用户ID'), sa.Column('path', sa.String(length=255), nullable=True, comment='请求路径'), sa.Column('ip', sa.String(length=255), nullable=True, comment='IP地址'), sa.Column('user_agent', sa.Text(), nullable=True, comment='用户代理'), sa.Column('headers', sa.Text(), nullable=True, comment='请求头'), sa.Column('query_params', sa.Text(), nullable=True, comment='请求参数'), sa.Column('body_params', sa.Text(), nullable=True, comment='请求体参数'), sa.Column('execution_time', sa.Float(), nullable=True, comment='执行时间(毫秒)'), sa.Column('response', sa.Text(), nullable=True, comment='响应结果'), sa.Column('exception', sa.Text(), nullable=True, comment='异常信息'), sa.Column('success', sa.Boolean(), nullable=True, comment='是否成功'), sa.Column('desc', sa.Text(), nullable=True, comment='描述'), sa.Column('type', sa.Enum('SYSTEM', 'AUTH', 'OPERATION', 'AUDIT', 'SECURITY', 'JOB', 'API', 'DB', 'PAYMENT', 'MESSAGE', 'OSS', 'OTHER', name='logtype'), nullable=False, comment='日志类型'), sa.Column('id', sa.String(length=36), nullable=False, comment='标识'), sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'), sa.Column('created_by', sa.String(length=36), nullable=True, comment='创建人'), sa.Column('updated_at', sa.DateTime(), nullable=False, comment='更新时间'), sa.Column('updated_by', sa.String(length=36), nullable=True, comment='更新人'), sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'), sa.PrimaryKeyConstraint('id', name=op.f('pk_sys_log')), mysql_charset='utf8mb4', mysql_collate='utf8mb4_general_ci' ) with op.batch_alter_table('sys_log', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_sys_log_created_by'), ['created_by'], unique=False) batch_op.create_index(batch_op.f('ix_sys_log_updated_by'), ['updated_by'], unique=False) op.create_table('sys_menu', sa.Column('id', sa.String(length=36), nullable=False, comment='标识'), sa.Column('name', sa.String(length=255), nullable=False, comment='菜单名称'), sa.Column('type', sa.Enum('catalog', 'menu', 'button', 'embedded', 'link', name='menutypeenum'), nullable=False, comment='菜单类型'), sa.Column('path', sa.String(length=255), nullable=True, comment='菜单路径'), sa.Column('component', sa.String(length=255), nullable=True, comment='菜单组件'), sa.Column('redirect', sa.String(length=255), nullable=True, comment='菜单重定向'), sa.Column('sort', sa.Integer(), nullable=False, comment='排序'), sa.Column('auth_code', sa.String(length=128), nullable=True, comment='权限编码'), sa.Column('meta', sa.JSON(), nullable=True, comment='菜单元数据'), sa.Column('status', sa.Enum('enabled', 'disabled', name='statusenum'), nullable=False, comment='状态'), sa.Column('parent_id', sa.String(length=36), nullable=True, comment='父菜单ID'), sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'), sa.Column('updated_at', sa.DateTime(), nullable=False, comment='更新时间'), sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'), sa.PrimaryKeyConstraint('id', name=op.f('pk_sys_menu')), sa.UniqueConstraint('name', name=op.f('uq_sys_menu_name')), mysql_charset='utf8mb4', mysql_collate='utf8mb4_general_ci' ) op.create_table('sys_role', sa.Column('name', sa.String(length=64), nullable=False, comment='名称'), sa.Column('code', sa.String(length=64), nullable=False, comment='编码'), sa.Column('desc', sa.Text(), nullable=True, comment='描述'), sa.Column('sort', sa.Integer(), nullable=False, comment='排序'), sa.Column('status', sa.Enum('enabled', 'disabled', name='statusenum'), nullable=False, comment='状态'), sa.Column('id', sa.String(length=36), nullable=False, comment='标识'), sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'), sa.Column('created_by', sa.String(length=36), nullable=True, comment='创建人'), sa.Column('updated_at', sa.DateTime(), nullable=False, comment='更新时间'), sa.Column('updated_by', sa.String(length=36), nullable=True, comment='更新人'), sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'), sa.PrimaryKeyConstraint('id', name=op.f('pk_sys_role')), sa.UniqueConstraint('code', name=op.f('uq_sys_role_code')), mysql_charset='utf8mb4', mysql_collate='utf8mb4_general_ci' ) with op.batch_alter_table('sys_role', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_sys_role_created_by'), ['created_by'], unique=False) batch_op.create_index(batch_op.f('ix_sys_role_updated_by'), ['updated_by'], unique=False) op.create_table('sys_role_menu', sa.Column('role_id', sa.String(length=36), nullable=False, comment='角色ID'), sa.Column('menu_id', sa.String(length=36), nullable=False, comment='菜单ID'), sa.PrimaryKeyConstraint('role_id', 'menu_id', name=op.f('pk_sys_role_menu')) ) op.create_table('sys_user', sa.Column('username', sa.String(length=64), nullable=False, comment='用户名'), sa.Column('phone', sa.String(length=13), nullable=True, comment='手机号'), sa.Column('email', sa.String(length=255), nullable=True, comment='邮箱'), sa.Column('password', sa.String(length=255), nullable=False, comment='密码'), sa.Column('realname', sa.String(length=32), nullable=True, comment='真实姓名'), sa.Column('desc', sa.Text(), nullable=True, comment='描述'), sa.Column('avatar', sa.String(length=255), nullable=True, comment='头像'), sa.Column('gender', sa.Enum('male', 'female', 'secure', name='genderenum'), nullable=False, comment='性别'), sa.Column('status', sa.Enum('enabled', 'disabled', name='statusenum'), nullable=False, comment='状态'), sa.Column('id', sa.String(length=36), nullable=False, comment='标识'), sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'), sa.Column('created_by', sa.String(length=36), nullable=True, comment='创建人'), sa.Column('updated_at', sa.DateTime(), nullable=False, comment='更新时间'), sa.Column('updated_by', sa.String(length=36), nullable=True, comment='更新人'), sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'), sa.PrimaryKeyConstraint('id', name=op.f('pk_sys_user')), mysql_charset='utf8mb4', mysql_collate='utf8mb4_general_ci' ) with op.batch_alter_table('sys_user', schema=None) as batch_op: batch_op.create_index(batch_op.f('ix_sys_user_created_by'), ['created_by'], unique=False) batch_op.create_index(batch_op.f('ix_sys_user_updated_by'), ['updated_by'], unique=False) op.create_table('sys_user_dept', sa.Column('user_id', sa.String(length=36), nullable=False, comment='用户ID'), sa.Column('dept_id', sa.String(length=36), nullable=False, comment='部门ID'), sa.PrimaryKeyConstraint('user_id', 'dept_id', name=op.f('pk_sys_user_dept')) ) op.create_table('sys_user_role', sa.Column('user_id', sa.String(length=36), nullable=False, comment='用户ID'), sa.Column('role_id', sa.String(length=36), nullable=False, comment='角色ID'), sa.PrimaryKeyConstraint('user_id', 'role_id', name=op.f('pk_sys_user_role')) ) op.create_table('sys_user_attribute', sa.Column('user_id', sa.String(length=36), nullable=False, comment='用户ID'), sa.Column('attr_group', sa.String(length=64), nullable=False, comment='属性分组(如: erp, custom)'), sa.Column('attr_key', sa.String(length=128), nullable=False, comment='属性键'), sa.Column('attr_value', sa.Text(), nullable=True, comment='属性值'), sa.Column('attr_type', sa.String(length=32), nullable=False, comment='值类型(string/int/float/bool/json/encrypted)'), sa.Column('description', sa.String(length=255), nullable=True, comment='属性描述'), sa.Column('sort', sa.Integer(), nullable=False, comment='排序'), sa.Column('id', sa.String(length=36), nullable=False, comment='标识'), sa.Column('created_at', sa.DateTime(), nullable=False, comment='创建时间'), sa.Column('created_by', sa.String(length=36), nullable=True, comment='创建人'), sa.Column('updated_at', sa.DateTime(), nullable=False, comment='更新时间'), sa.Column('updated_by', sa.String(length=36), nullable=True, comment='更新人'), sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'), sa.ForeignKeyConstraint(['user_id'], ['sys_user.id'], name=op.f('fk_sys_user_attribute_user_id_sys_user'), ondelete='CASCADE'), sa.PrimaryKeyConstraint('id', name=op.f('pk_sys_user_attribute')), sa.UniqueConstraint('user_id', 'attr_group', 'attr_key', name='uk_user_group_key') ) with op.batch_alter_table('sys_user_attribute', schema=None) as batch_op: batch_op.create_index('idx_user_group_key', ['user_id', 'attr_group', 'attr_key'], unique=False) batch_op.create_index(batch_op.f('ix_sys_user_attribute_attr_group'), ['attr_group'], unique=False) batch_op.create_index(batch_op.f('ix_sys_user_attribute_created_by'), ['created_by'], unique=False) batch_op.create_index(batch_op.f('ix_sys_user_attribute_updated_by'), ['updated_by'], unique=False) batch_op.create_index(batch_op.f('ix_sys_user_attribute_user_id'), ['user_id'], unique=False) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### with op.batch_alter_table('sys_user_attribute', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_sys_user_attribute_user_id')) batch_op.drop_index(batch_op.f('ix_sys_user_attribute_updated_by')) batch_op.drop_index(batch_op.f('ix_sys_user_attribute_created_by')) batch_op.drop_index(batch_op.f('ix_sys_user_attribute_attr_group')) batch_op.drop_index('idx_user_group_key') op.drop_table('sys_user_attribute') op.drop_table('sys_user_role') op.drop_table('sys_user_dept') with op.batch_alter_table('sys_user', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_sys_user_updated_by')) batch_op.drop_index(batch_op.f('ix_sys_user_created_by')) op.drop_table('sys_user') op.drop_table('sys_role_menu') with op.batch_alter_table('sys_role', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_sys_role_updated_by')) batch_op.drop_index(batch_op.f('ix_sys_role_created_by')) op.drop_table('sys_role') op.drop_table('sys_menu') with op.batch_alter_table('sys_log', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_sys_log_updated_by')) batch_op.drop_index(batch_op.f('ix_sys_log_created_by')) op.drop_table('sys_log') with op.batch_alter_table('sys_file_directory', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_sys_file_directory_updated_by')) batch_op.drop_index('ix_sys_file_directory_path', mysql_length=255) batch_op.drop_index(batch_op.f('ix_sys_file_directory_created_by')) op.drop_table('sys_file_directory') with op.batch_alter_table('sys_file', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_sys_file_updated_by')) batch_op.drop_index(batch_op.f('ix_sys_file_share_code')) batch_op.drop_index(batch_op.f('ix_sys_file_file_key')) batch_op.drop_index(batch_op.f('ix_sys_file_file_hash')) batch_op.drop_index(batch_op.f('ix_sys_file_directory_id')) batch_op.drop_index(batch_op.f('ix_sys_file_created_by')) op.drop_table('sys_file') with op.batch_alter_table('sys_dict_type', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_sys_dict_type_updated_by')) batch_op.drop_index(batch_op.f('ix_sys_dict_type_created_by')) op.drop_table('sys_dict_type') with op.batch_alter_table('sys_dict_data', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_sys_dict_data_updated_by')) batch_op.drop_index(batch_op.f('ix_sys_dict_data_created_by')) op.drop_table('sys_dict_data') op.drop_table('sys_dept') with op.batch_alter_table('sys_config', schema=None) as batch_op: batch_op.drop_index(batch_op.f('ix_sys_config_updated_by')) batch_op.drop_index(batch_op.f('ix_sys_config_created_by')) op.drop_table('sys_config') # ### end Alembic commands ###