-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update direct paging integration non-default route data
- Loading branch information
1 parent
2581d64
commit 8b07315
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
engine/apps/alerts/migrations/0073_update_direct_paging_integration_non_default_routes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Generated by Django 4.2.17 on 2025-01-06 15:48 | ||
|
||
import logging | ||
|
||
from django.db import migrations | ||
from django.db.models import Subquery, OuterRef | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def update_direct_paging_integration_non_default_routes(apps, schema_editor): | ||
""" | ||
If any of the original Direct Paging integration default routes had chatops settings or escalation chains | ||
associated with them, simply set the non-default route to have the same settings. This will avoid any functional | ||
differences should users start paging a team using the "important" functionality. | ||
""" | ||
ChannelFilter = apps.get_model("alerts", "ChannelFilter") | ||
|
||
logger.info("Starting update_direct_paging_integration_non_default_routes migration...") | ||
|
||
# Subquery that selects the matching "default" channel filter for each non-default filter | ||
default_route_subquery = ChannelFilter.objects.filter( | ||
alert_receive_channel=OuterRef("alert_receive_channel"), | ||
is_default=True | ||
) | ||
|
||
# Perform a bulk update on all non-default routes in one go | ||
updated_count = ( | ||
ChannelFilter.objects | ||
.filter( | ||
alert_receive_channel__integration="direct_paging", | ||
is_default=False | ||
) | ||
.update( | ||
escalation_chain_id=Subquery(default_route_subquery.values("escalation_chain_id")[:1]), | ||
telegram_channel_id=Subquery(default_route_subquery.values("telegram_channel_id")[:1]), | ||
slack_channel_id=Subquery(default_route_subquery.values("slack_channel_id")[:1]), | ||
) | ||
) | ||
|
||
logger.info(f"Updated {updated_count} non-default direct paging integration routes") | ||
logger.info("Finished update_direct_paging_integration_non_default_routes migration.") | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("alerts", "0072_upsert_direct_paging_integration_routes"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(update_direct_paging_integration_non_default_routes, migrations.RunPython.noop), | ||
] |