"""add_user_role Revision ID: 4e40432cab9f Revises: 4bd4c7f26818 Create Date: 2026-09-02 10:29:41.369850 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import mysql # revision identifiers, used by Alembic. revision: str = '4e40432cab9f' down_revision: Union[str, None] = '4bd4c7f26818' branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.alter_column('document_categories', 'path', existing_type=mysql.VARCHAR(collation='utf8mb4_unicode_ci', length=500), comment='物化路径,如 /01_公司层/04_岗位AI角色/', existing_comment='物化路径', existing_nullable=False, existing_server_default=sa.text("'/'")) op.alter_column('document_categories', 'is_folder', existing_type=mysql.TINYINT(display_width=1), comment='True=文件夹(可含子项),False=叶子分类', existing_comment='True=文件夹', existing_nullable=False, existing_server_default=sa.text("'1'")) op.create_foreign_key(None, 'document_categories', 'document_categories', ['parent_id'], ['id']) op.alter_column('documents', 'original_filename', existing_type=mysql.VARCHAR(collation='utf8mb4_unicode_ci', length=512), comment='原始文件名或文本标题 (仅展示)', existing_comment='原始文件名 (仅展示)', existing_nullable=False) op.alter_column('documents', 'storage_path', existing_type=mysql.VARCHAR(collation='utf8mb4_unicode_ci', length=1024), comment='相对于 data/ 的物理存储路径(文本内容文档为 NULL)', existing_nullable=True) op.alter_column('documents', 'content', existing_type=mysql.TEXT(collation='utf8mb4_unicode_ci'), comment='直接输入的文本内容(非文件上传时使用)', existing_comment='直接输入的文本内容', existing_nullable=True) op.alter_column('documents', 'content_format', existing_type=mysql.VARCHAR(collation='utf8mb4_unicode_ci', length=16), comment='内容格式:markdown / text', existing_comment='内容格式', existing_nullable=False, existing_server_default=sa.text("'markdown'")) op.alter_column('documents', 'file_size', existing_type=mysql.INTEGER(), comment='文件大小 (字节),文本内容文档为内容长度', existing_comment='文件大小 (字节)', existing_nullable=False) op.alter_column('documents', 'file_ext', existing_type=mysql.VARCHAR(collation='utf8mb4_unicode_ci', length=16), comment='文件扩展名 (.docx/.pdf/.md)', existing_comment='文件扩展名 (.docx/.pdf)', existing_nullable=False) op.alter_column('documents', 'sha256', existing_type=mysql.VARCHAR(collation='utf8mb4_unicode_ci', length=64), comment='文件 SHA-256 哈希(文本内容文档为 NULL)', existing_nullable=True) op.add_column('users', sa.Column('role', sa.String(length=16), nullable=False, comment='角色 (internal=内部员工 / customer=客户)')) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.drop_column('users', 'role') op.alter_column('documents', 'sha256', existing_type=mysql.VARCHAR(collation='utf8mb4_unicode_ci', length=64), comment=None, existing_comment='文件 SHA-256 哈希(文本内容文档为 NULL)', existing_nullable=True) op.alter_column('documents', 'file_ext', existing_type=mysql.VARCHAR(collation='utf8mb4_unicode_ci', length=16), comment='文件扩展名 (.docx/.pdf)', existing_comment='文件扩展名 (.docx/.pdf/.md)', existing_nullable=False) op.alter_column('documents', 'file_size', existing_type=mysql.INTEGER(), comment='文件大小 (字节)', existing_comment='文件大小 (字节),文本内容文档为内容长度', existing_nullable=False) op.alter_column('documents', 'content_format', existing_type=mysql.VARCHAR(collation='utf8mb4_unicode_ci', length=16), comment='内容格式', existing_comment='内容格式:markdown / text', existing_nullable=False, existing_server_default=sa.text("'markdown'")) op.alter_column('documents', 'content', existing_type=mysql.TEXT(collation='utf8mb4_unicode_ci'), comment='直接输入的文本内容', existing_comment='直接输入的文本内容(非文件上传时使用)', existing_nullable=True) op.alter_column('documents', 'storage_path', existing_type=mysql.VARCHAR(collation='utf8mb4_unicode_ci', length=1024), comment=None, existing_comment='相对于 data/ 的物理存储路径(文本内容文档为 NULL)', existing_nullable=True) op.alter_column('documents', 'original_filename', existing_type=mysql.VARCHAR(collation='utf8mb4_unicode_ci', length=512), comment='原始文件名 (仅展示)', existing_comment='原始文件名或文本标题 (仅展示)', existing_nullable=False) op.drop_constraint(None, 'document_categories', type_='foreignkey') op.alter_column('document_categories', 'is_folder', existing_type=mysql.TINYINT(display_width=1), comment='True=文件夹', existing_comment='True=文件夹(可含子项),False=叶子分类', existing_nullable=False, existing_server_default=sa.text("'1'")) op.alter_column('document_categories', 'path', existing_type=mysql.VARCHAR(collation='utf8mb4_unicode_ci', length=500), comment='物化路径', existing_comment='物化路径,如 /01_公司层/04_岗位AI角色/', existing_nullable=False, existing_server_default=sa.text("'/'")) # ### end Alembic commands ###