Coverage for mcpgateway/alembic/versions/e75490e949b1_add_improved_status_to_tables.py: 53%
17 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-09 11:03 +0100
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-09 11:03 +0100
1# -*- coding: utf-8 -*-
2"""Add enabled and reachable columns in tools and gateways tables and migrate data (is_active ➜ enabled,reachable).
4Revision ID: e75490e949b1
5Revises: e4fc04d1a442
6Create Date: 2025-07-02 17:12:40.678256
7"""
9# Standard
10from typing import Sequence, Union
12# Third-Party
13import sqlalchemy as sa
15# First-Party
16# Alembic / SQLAlchemy
17from alembic import op
19# Revision identifiers.
20revision: str = "e75490e949b1"
21down_revision: Union[str, Sequence[str], None] = "e4fc04d1a442"
22branch_labels: Union[str, Sequence[str], None] = None
23depends_on: Union[str, Sequence[str], None] = None
26def upgrade():
27 """
28 Renames 'is_active' to 'enabled' and adds a new 'reachable' column (default True)
29 in both 'tools' and 'gateways' tables.
30 """
31 op.alter_column("tools", "is_active", new_column_name="enabled")
32 op.add_column("tools", sa.Column("reachable", sa.Boolean(), nullable=False, server_default=sa.true()))
34 op.alter_column("gateways", "is_active", new_column_name="enabled")
35 op.add_column("gateways", sa.Column("reachable", sa.Boolean(), nullable=False, server_default=sa.true()))
38def downgrade():
39 """
40 Reverts the changes by renaming 'enabled' back to 'is_active'
41 and dropping the 'reachable' column in both 'tools' and 'gateways' tables.
42 """
43 op.alter_column("tools", "enabled", new_column_name="is_active")
44 op.drop_column("tools", "reachable")
46 op.alter_column("gateways", "enabled", new_column_name="is_active")
47 op.drop_column("gateways", "reachable")