Files
replypier/backend/alembic/versions/621095beb234_add_mcp_tools_tables.py
T

84 lines
3.3 KiB
Python
Raw Normal View History

"""
Copyright 2024-2026 ChatterMate
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
"""add_mcp_tools_tables
Revision ID: 621095beb234
Revises: 7991b4fc00d8
Create Date: 2025-07-27 16:45:37.520270
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '621095beb234'
down_revision: Union[str, None] = '7991b4fc00d8'
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('mcp_tools',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('transport_type', sa.Enum('STDIO', 'SSE', 'HTTP', name='mcptransporttype'), nullable=False),
sa.Column('enabled', sa.Boolean(), nullable=False),
sa.Column('command', sa.String(), nullable=True),
sa.Column('args', postgresql.JSON(astext_type=sa.Text()), nullable=True),
sa.Column('env_vars', postgresql.JSON(astext_type=sa.Text()), nullable=True),
sa.Column('url', sa.String(), nullable=True),
sa.Column('headers', postgresql.JSON(astext_type=sa.Text()), nullable=True),
sa.Column('timeout', sa.Integer(), nullable=True),
sa.Column('sse_read_timeout', sa.Integer(), nullable=True),
sa.Column('terminate_on_close', sa.Boolean(), nullable=True),
sa.Column('organization_id', sa.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
sa.ForeignKeyConstraint(['organization_id'], ['organizations.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_mcp_tools_id'), 'mcp_tools', ['id'], unique=False)
op.create_table('mcp_tool_to_agent',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('mcp_tool_id', sa.Integer(), nullable=False),
sa.Column('agent_id', sa.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
sa.ForeignKeyConstraint(['agent_id'], ['agents.id'], ),
sa.ForeignKeyConstraint(['mcp_tool_id'], ['mcp_tools.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_mcp_tool_to_agent_id'), 'mcp_tool_to_agent', ['id'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_mcp_tool_to_agent_id'), table_name='mcp_tool_to_agent')
op.drop_table('mcp_tool_to_agent')
op.drop_index(op.f('ix_mcp_tools_id'), table_name='mcp_tools')
op.drop_table('mcp_tools')
# ### end Alembic commands ###