"""Add supportteams.webhookurl (per-team alert webhook)

A support team can carry a Teams (or other) webhook; alerting plugins route
alerts to a team by selecting it. Nullable. Idempotent guard.

Revision ID: 7d29_supportteam_webhookurl
Revises: 7d28_dashboarddefault_displayrole
Create Date: 2026-07-22

"""
from alembic import op
import sqlalchemy as sa


revision = '7d29_supportteam_webhookurl'
down_revision = '7d28_dashboarddefault_displayrole'
branch_labels = None
depends_on = None


def _has_col(insp):
    return any(c['name'] == 'webhookurl'
               for c in insp.get_columns('supportteams'))


def upgrade():
    bind = op.get_bind()
    insp = sa.inspect(bind)
    if 'supportteams' not in insp.get_table_names():
        return
    if not _has_col(insp):
        op.add_column('supportteams', sa.Column('webhookurl', sa.Text(), nullable=True))


def downgrade():
    bind = op.get_bind()
    insp = sa.inspect(bind)
    if 'supportteams' not in insp.get_table_names():
        return
    if _has_col(insp):
        op.drop_column('supportteams', 'webhookurl')
