Coverage for mcpgateway/alembic/versions/e75490e949b1_add_improved_status_to_tables.py: 53%

1# -*- coding: utf-8 -*-

2"""Add enabled and reachable columns in tools and gateways tables and migrate data (is_active ➜ enabled,reachable).

3

4 Revision ID: e75490e949b1

5 Revises: e4fc04d1a442

6 Create Date: 2025-07-02 17:12:40.678256

7"""

8

9# Standard

10 from typing import Sequence, Union

11

12# Third-Party

13 import sqlalchemy as sa

14

15# First-Party

16# Alembic / SQLAlchemy

17 from alembic import op

18

19# Revision identifiers.

20 revision: str = "e75490e949b1"

21 down_revision: Union[str, Sequence[str], None] = "e4fc04d1a442"

22 branch_labels: Union[str, Sequence[str], None] = None

23 depends_on: Union[str, Sequence[str], None] = None

24

25

26 def 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()))

33

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()))

36

37

38 def 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")

45

46 op.alter_column("gateways", "enabled", new_column_name="is_active")

47 op.drop_column("gateways", "reachable")