Files
NexaPG/backend/alembic/versions/0005_target_owners_notifications.py
nessi ea26ef4d33
All checks were successful
PostgreSQL Compatibility Matrix / PG14 smoke (push) Successful in 8s
PostgreSQL Compatibility Matrix / PG15 smoke (push) Successful in 7s
PostgreSQL Compatibility Matrix / PG16 smoke (push) Successful in 7s
PostgreSQL Compatibility Matrix / PG17 smoke (push) Successful in 6s
PostgreSQL Compatibility Matrix / PG18 smoke (push) Successful in 6s
Add target owners and alert notification management.
This commit implements the addition of `target_owners` and `alert_notification_events` tables, enabling management of responsible users for targets. Backend and frontend components are updated to allow viewing, assigning, and notifying target owners about critical alerts via email.
2026-02-12 15:22:32 +01:00

59 lines
2.8 KiB
Python

"""add target owners and alert notification events
Revision ID: 0005_target_owners
Revises: 0004_email_settings
Create Date: 2026-02-12
"""
from alembic import op
import sqlalchemy as sa
revision = "0005_target_owners"
down_revision = "0004_email_settings"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.create_table(
"target_owners",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("target_id", sa.Integer(), nullable=False),
sa.Column("user_id", sa.Integer(), nullable=False),
sa.Column("assigned_by_user_id", sa.Integer(), nullable=True),
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.ForeignKeyConstraint(["assigned_by_user_id"], ["users.id"], ondelete="SET NULL"),
sa.ForeignKeyConstraint(["target_id"], ["targets.id"], ondelete="CASCADE"),
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("target_id", "user_id", name="uq_target_owner_target_user"),
)
op.create_index(op.f("ix_target_owners_target_id"), "target_owners", ["target_id"], unique=False)
op.create_index(op.f("ix_target_owners_user_id"), "target_owners", ["user_id"], unique=False)
op.create_table(
"alert_notification_events",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("alert_key", sa.String(length=200), nullable=False),
sa.Column("target_id", sa.Integer(), nullable=False),
sa.Column("severity", sa.String(length=16), nullable=False),
sa.Column("last_seen_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column("last_sent_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.ForeignKeyConstraint(["target_id"], ["targets.id"], ondelete="CASCADE"),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("alert_key", "target_id", "severity", name="uq_alert_notif_event_key_target_sev"),
)
op.create_index(op.f("ix_alert_notification_events_alert_key"), "alert_notification_events", ["alert_key"], unique=False)
op.create_index(op.f("ix_alert_notification_events_target_id"), "alert_notification_events", ["target_id"], unique=False)
def downgrade() -> None:
op.drop_index(op.f("ix_alert_notification_events_target_id"), table_name="alert_notification_events")
op.drop_index(op.f("ix_alert_notification_events_alert_key"), table_name="alert_notification_events")
op.drop_table("alert_notification_events")
op.drop_index(op.f("ix_target_owners_user_id"), table_name="target_owners")
op.drop_index(op.f("ix_target_owners_target_id"), table_name="target_owners")
op.drop_table("target_owners")