42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
"""Add indexes for structured tool health events.
|
|
|
|
Revision ID: 0040
|
|
Revises: 0039
|
|
Create Date: 2026-09-03
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
|
|
revision: str = "0040"
|
|
down_revision: Union[str, None] = "0039"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_index(
|
|
"ix_usage_health_kind_created",
|
|
"usage_events",
|
|
["kind", "created_at"],
|
|
postgresql_where=sa.text(
|
|
"kind IN ('tool_failure', 'tool_malformed', 'tool_salvaged', "
|
|
"'run_error', 'empty_response', 'run_stopped', 'agent_guard', "
|
|
"'context_fold_failure', 'quality_gate')"
|
|
),
|
|
)
|
|
op.create_index(
|
|
"ux_usage_tool_failure_message",
|
|
"usage_events",
|
|
["message_id"],
|
|
unique=True,
|
|
postgresql_where=sa.text("kind IN ('tool_failure', 'quality_gate')"),
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ux_usage_tool_failure_message", table_name="usage_events")
|
|
op.drop_index("ix_usage_health_kind_created", table_name="usage_events")
|