"""Phase 14.1 — PSP Management schema (additive)."""
from alembic import op
from app.core.database import Base
import app.models  # noqa: F401

revision = "0002_phase_141_psp"
down_revision = "0001_initial"
branch_labels = None
depends_on = None

_PSP_TABLES = (
    "psp_connections",
    "psp_credential_vault_refs",
    "psp_connection_health_checks",
    "psp_routing_policies",
)


def upgrade():
    bind = op.get_bind()
    Base.metadata.create_all(bind=bind)


def downgrade():
    bind = op.get_bind()
    for name in reversed(_PSP_TABLES):
        table = Base.metadata.tables.get(name)
        if table is not None:
            table.drop(bind=bind, checkfirst=True)
