From 660e1037d6768fab7da773c7cd6ba5bc76e1f40a Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 20 Dec 2025 16:14:44 +0800 Subject: [PATCH] [add] migration script --- .../versions/022550fdcfda_202512201613.py | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 api/migrations/versions/022550fdcfda_202512201613.py diff --git a/api/migrations/versions/022550fdcfda_202512201613.py b/api/migrations/versions/022550fdcfda_202512201613.py new file mode 100644 index 00000000..2d031690 --- /dev/null +++ b/api/migrations/versions/022550fdcfda_202512201613.py @@ -0,0 +1,116 @@ +"""202512201613 + +Revision ID: 022550fdcfda +Revises: 626abf154a6a +Create Date: 2025-12-20 16:14:04.121139 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = '022550fdcfda' +down_revision: Union[str, None] = '626abf154a6a' +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.create_table('tool_configs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('name', sa.String(length=255), nullable=False), + sa.Column('description', sa.Text(), nullable=True), + sa.Column('tool_type', sa.String(length=50), nullable=False), + sa.Column('tenant_id', sa.UUID(), nullable=False), + sa.Column('status', sa.String(length=50), nullable=False), + sa.Column('config_data', sa.JSON(), nullable=True), + sa.Column('version', sa.String(length=50), nullable=True), + sa.Column('tags', sa.JSON(), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=False), + sa.Column('updated_at', sa.DateTime(), nullable=False), + sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_tool_configs_name'), 'tool_configs', ['name'], unique=False) + op.create_index(op.f('ix_tool_configs_status'), 'tool_configs', ['status'], unique=False) + op.create_index(op.f('ix_tool_configs_tenant_id'), 'tool_configs', ['tenant_id'], unique=False) + op.create_index(op.f('ix_tool_configs_tool_type'), 'tool_configs', ['tool_type'], unique=False) + op.create_table('builtin_tool_configs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('tool_class', sa.String(length=255), nullable=False), + sa.Column('parameters', sa.JSON(), nullable=True), + sa.ForeignKeyConstraint(['id'], ['tool_configs.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('custom_tool_configs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('schema_url', sa.String(length=1000), nullable=True), + sa.Column('schema_content', sa.JSON(), nullable=True), + sa.Column('auth_type', sa.String(length=50), nullable=False), + sa.Column('auth_config', sa.JSON(), nullable=True), + sa.Column('base_url', sa.String(length=1000), nullable=True), + sa.Column('timeout', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['id'], ['tool_configs.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('mcp_tool_configs', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('server_url', sa.String(length=1000), nullable=False), + sa.Column('connection_config', sa.JSON(), nullable=True), + sa.Column('last_health_check', sa.DateTime(), nullable=True), + sa.Column('health_status', sa.String(length=50), nullable=True), + sa.Column('error_message', sa.Text(), nullable=True), + sa.Column('available_tools', sa.JSON(), nullable=True), + sa.ForeignKeyConstraint(['id'], ['tool_configs.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('tool_executions', + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('tool_config_id', sa.UUID(), nullable=False), + sa.Column('execution_id', sa.String(length=255), nullable=False), + sa.Column('status', sa.String(length=50), nullable=False), + sa.Column('input_data', sa.JSON(), nullable=True), + sa.Column('output_data', sa.JSON(), nullable=True), + sa.Column('error_message', sa.Text(), nullable=True), + sa.Column('started_at', sa.DateTime(), nullable=False), + sa.Column('completed_at', sa.DateTime(), nullable=True), + sa.Column('execution_time', sa.Float(), nullable=True), + sa.Column('token_usage', sa.JSON(), nullable=True), + sa.Column('user_id', sa.UUID(), nullable=True), + sa.Column('workspace_id', sa.UUID(), nullable=False), + sa.ForeignKeyConstraint(['tool_config_id'], ['tool_configs.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), + sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_tool_executions_execution_id'), 'tool_executions', ['execution_id'], unique=False) + op.create_index(op.f('ix_tool_executions_started_at'), 'tool_executions', ['started_at'], unique=False) + op.create_index(op.f('ix_tool_executions_status'), 'tool_executions', ['status'], unique=False) + op.create_index(op.f('ix_tool_executions_tool_config_id'), 'tool_executions', ['tool_config_id'], unique=False) + op.create_index(op.f('ix_tool_executions_user_id'), 'tool_executions', ['user_id'], unique=False) + op.create_index(op.f('ix_tool_executions_workspace_id'), 'tool_executions', ['workspace_id'], unique=False) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_tool_executions_workspace_id'), table_name='tool_executions') + op.drop_index(op.f('ix_tool_executions_user_id'), table_name='tool_executions') + op.drop_index(op.f('ix_tool_executions_tool_config_id'), table_name='tool_executions') + op.drop_index(op.f('ix_tool_executions_status'), table_name='tool_executions') + op.drop_index(op.f('ix_tool_executions_started_at'), table_name='tool_executions') + op.drop_index(op.f('ix_tool_executions_execution_id'), table_name='tool_executions') + op.drop_table('tool_executions') + op.drop_table('mcp_tool_configs') + op.drop_table('custom_tool_configs') + op.drop_table('builtin_tool_configs') + op.drop_index(op.f('ix_tool_configs_tool_type'), table_name='tool_configs') + op.drop_index(op.f('ix_tool_configs_tenant_id'), table_name='tool_configs') + op.drop_index(op.f('ix_tool_configs_status'), table_name='tool_configs') + op.drop_index(op.f('ix_tool_configs_name'), table_name='tool_configs') + op.drop_table('tool_configs') + # ### end Alembic commands ###