49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
"""ingress org/service + incident dimensions for multi-grafana
|
|
|
|
Revision ID: 003_ingress_org
|
|
Revises: 002_irm_core
|
|
Create Date: 2026-04-03
|
|
|
|
"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
|
|
revision: str = "003_ingress_org"
|
|
down_revision: Union[str, None] = "002_irm_core"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.execute(
|
|
"""
|
|
ALTER TABLE ingress_events
|
|
ADD COLUMN IF NOT EXISTS org_slug text,
|
|
ADD COLUMN IF NOT EXISTS service_name text;
|
|
"""
|
|
)
|
|
op.execute(
|
|
"""
|
|
ALTER TABLE incidents
|
|
ADD COLUMN IF NOT EXISTS grafana_org_slug text,
|
|
ADD COLUMN IF NOT EXISTS service_name text;
|
|
"""
|
|
)
|
|
op.execute(
|
|
"""
|
|
CREATE INDEX IF NOT EXISTS incidents_org_service_idx
|
|
ON incidents (grafana_org_slug, service_name)
|
|
WHERE grafana_org_slug IS NOT NULL OR service_name IS NOT NULL;
|
|
"""
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.execute("DROP INDEX IF EXISTS incidents_org_service_idx;")
|
|
op.execute("ALTER TABLE incidents DROP COLUMN IF EXISTS service_name;")
|
|
op.execute("ALTER TABLE incidents DROP COLUMN IF EXISTS grafana_org_slug;")
|
|
op.execute("ALTER TABLE ingress_events DROP COLUMN IF EXISTS service_name;")
|
|
op.execute("ALTER TABLE ingress_events DROP COLUMN IF EXISTS org_slug;")
|