55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
"""add tools table
|
||
|
||
Revision ID: 004
|
||
Revises: 003
|
||
Create Date: 2026-01-23 00:00:00.000000
|
||
|
||
"""
|
||
from alembic import op
|
||
import sqlalchemy as sa
|
||
from sqlalchemy.dialects.mysql import CHAR, JSON
|
||
|
||
|
||
# revision identifiers, used by Alembic.
|
||
revision = '004_add_tools_table'
|
||
down_revision = '003_add_rbac'
|
||
branch_labels = None
|
||
depends_on = None
|
||
|
||
|
||
def upgrade():
|
||
# 创建tools表
|
||
op.create_table(
|
||
'tools',
|
||
sa.Column('id', CHAR(36), primary_key=True, comment='工具ID'),
|
||
sa.Column('name', sa.String(100), nullable=False, unique=True, comment='工具名称'),
|
||
sa.Column('description', sa.Text, nullable=False, comment='工具描述'),
|
||
sa.Column('category', sa.String(50), nullable=True, comment='工具分类'),
|
||
sa.Column('function_schema', JSON, nullable=False, comment='函数定义(JSON Schema)'),
|
||
sa.Column('implementation_type', sa.String(50), nullable=False, comment='实现类型: builtin/http/workflow/code'),
|
||
sa.Column('implementation_config', JSON, nullable=True, comment='实现配置'),
|
||
sa.Column('is_public', sa.Boolean, default=False, comment='是否公开'),
|
||
sa.Column('user_id', CHAR(36), sa.ForeignKey('users.id', ondelete='SET NULL'), nullable=True, comment='创建者ID'),
|
||
sa.Column('use_count', sa.Integer, default=0, comment='使用次数'),
|
||
sa.Column('created_at', sa.DateTime, server_default=sa.func.now(), comment='创建时间'),
|
||
sa.Column('updated_at', sa.DateTime, server_default=sa.func.now(), onupdate=sa.func.now(), comment='更新时间'),
|
||
mysql_engine='InnoDB',
|
||
mysql_charset='utf8mb4',
|
||
mysql_collate='utf8mb4_unicode_ci'
|
||
)
|
||
|
||
# 创建索引
|
||
op.create_index('idx_tools_category', 'tools', ['category'])
|
||
op.create_index('idx_tools_is_public', 'tools', ['is_public'])
|
||
op.create_index('idx_tools_user_id', 'tools', ['user_id'])
|
||
|
||
|
||
def downgrade():
|
||
# 删除索引
|
||
op.drop_index('idx_tools_user_id', table_name='tools')
|
||
op.drop_index('idx_tools_is_public', table_name='tools')
|
||
op.drop_index('idx_tools_category', table_name='tools')
|
||
|
||
# 删除表
|
||
op.drop_table('tools')
|