release: v1.10.0 — модуль команд (teams), team_id на алертах
- Alembic 006: teams, team_label_rules, irm_alerts.team_id - Вебхук: сопоставление команды по правилам лейблов (priority) - API/UI Команды; алерты: JOIN team, фильтр team_id - Тесты test_team_match, test_teams_api; обновлён test_root_ui Made-with: Cursor
This commit is contained in:
78
alembic/versions/006_teams.py
Normal file
78
alembic/versions/006_teams.py
Normal file
@ -0,0 +1,78 @@
|
||||
"""IRM: команды (teams) и правила сопоставления по лейблам алерта
|
||||
|
||||
Revision ID: 006_teams
|
||||
Revises: 005_irm_alerts
|
||||
Create Date: 2026-04-03
|
||||
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision: str = "006_teams"
|
||||
down_revision: Union[str, None] = "005_irm_alerts"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS teams (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
slug text NOT NULL UNIQUE,
|
||||
name text NOT NULL,
|
||||
description text,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS teams_slug_idx ON teams (slug);
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS team_label_rules (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
team_id uuid NOT NULL REFERENCES teams(id) ON DELETE CASCADE,
|
||||
label_key text NOT NULL,
|
||||
label_value text NOT NULL,
|
||||
priority integer NOT NULL DEFAULT 0,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
CONSTRAINT team_label_rules_key_nonempty CHECK (
|
||||
length(trim(label_key)) > 0
|
||||
)
|
||||
);
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS team_label_rules_team_idx ON team_label_rules (team_id);
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS team_label_rules_priority_idx
|
||||
ON team_label_rules (priority DESC, id ASC);
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
ALTER TABLE irm_alerts
|
||||
ADD COLUMN IF NOT EXISTS team_id uuid REFERENCES teams(id) ON DELETE SET NULL;
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS irm_alerts_team_id_idx ON irm_alerts (team_id);
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.execute("ALTER TABLE irm_alerts DROP COLUMN IF EXISTS team_id;")
|
||||
op.execute("DROP TABLE IF EXISTS team_label_rules;")
|
||||
op.execute("DROP TABLE IF EXISTS teams;")
|
||||
Reference in New Issue
Block a user