|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""Location: ./mcpgateway/alembic/versions/add_toolops_test_case_table.py |
| 3 | +Copyright 2025 |
| 4 | +SPDX-License-Identifier: Apache-2.0 |
| 5 | +Authors: Jay Bandlamudi |
| 6 | +
|
| 7 | +add_a2a_agents_and_metrics |
| 8 | +
|
| 9 | +Revision ID: add_a2a_agents_and_metrics |
| 10 | +Revises: add_oauth_tokens_table |
| 11 | +Create Date: 2025-11-27 10:00:00.000000 |
| 12 | +""" |
| 13 | + |
| 14 | +# Standard |
| 15 | +from typing import Sequence, Union |
| 16 | + |
| 17 | +# Third-Party |
| 18 | +from alembic import op |
| 19 | +import sqlalchemy as sa |
| 20 | + |
| 21 | +# revision identifiers, used by Alembic. |
| 22 | +revision: str = "add_toolops_test_cases_table" |
| 23 | +down_revision: Union[str, Sequence[str], None] = "z1a2b3c4d5e6" |
| 24 | +branch_labels: Union[str, Sequence[str], None] = None |
| 25 | +depends_on: Union[str, Sequence[str], None] = None |
| 26 | + |
| 27 | + |
| 28 | +def upgrade() -> None: |
| 29 | + """Add toolops test cases table""" |
| 30 | + |
| 31 | + # Check if table already exists (for development scenarios) |
| 32 | + conn = op.get_bind() |
| 33 | + inspector = sa.inspect(conn) |
| 34 | + existing_tables = inspector.get_table_names() |
| 35 | + |
| 36 | + if "toolops_test_cases" not in existing_tables: |
| 37 | + # Create a2a_agents table with unique constraints included (SQLite compatible) |
| 38 | + op.create_table( |
| 39 | + "toolops_test_cases", |
| 40 | + sa.Column("tool_id", sa.String(255), primary_key=True), |
| 41 | + sa.Column("test_cases", sa.JSON(), nullable=True), |
| 42 | + sa.Column("run_status", sa.String(255), nullable=True), |
| 43 | + ) |
| 44 | + |
| 45 | + |
| 46 | +def downgrade() -> None: |
| 47 | + """Reverse the toolops test cases tables.""" |
| 48 | + # Check if tables exist before trying to drop indexes/tables |
| 49 | + conn = op.get_bind() |
| 50 | + inspector = sa.inspect(conn) |
| 51 | + existing_tables = inspector.get_table_names() |
| 52 | + |
| 53 | + # Drop tables (if they exist) |
| 54 | + for table_name in ["toolops_test_cases"]: |
| 55 | + if table_name in existing_tables: |
| 56 | + try: |
| 57 | + op.drop_table(table_name) |
| 58 | + except Exception as e: |
| 59 | + print(f"Warning: Could not drop table {table_name}: {e}") |
0 commit comments