"""add ops alert events

Revision ID: 013_add_ops_alert_events
Revises: 012_add_telemetry_events
Create Date: 2025-12-15
"""

from __future__ import annotations

from alembic import op
import sqlalchemy as sa


revision = "013_add_ops_alert_events"
down_revision = "012_add_telemetry_events"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        "ops_alert_events",
        sa.Column("id", sa.Integer(), primary_key=True),
        sa.Column("alert_key", sa.String(length=80), nullable=False),
        sa.Column("severity", sa.String(length=10), nullable=False),
        sa.Column("title", sa.String(length=200), nullable=False),
        sa.Column("detail", sa.Text(), nullable=True),
        sa.Column("status", sa.String(length=20), nullable=False),
        sa.Column("recipients", sa.Text(), nullable=True),
        sa.Column("send_reason", sa.String(length=60), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False, server_default=sa.text("now()")),
    )
    op.create_index("ix_ops_alert_key_created", "ops_alert_events", ["alert_key", "created_at"])
    op.create_index("ix_ops_alert_status_created", "ops_alert_events", ["status", "created_at"])


def downgrade() -> None:
    op.drop_index("ix_ops_alert_status_created", table_name="ops_alert_events")
    op.drop_index("ix_ops_alert_key_created", table_name="ops_alert_events")
    op.drop_table("ops_alert_events")

