From 49578517406c78de195749fc8a69baca7ef12ac6 Mon Sep 17 00:00:00 2001 From: Ildar Iskhakov Date: Thu, 10 Oct 2024 19:15:42 +0800 Subject: [PATCH] Remove resolved_by_alert field from state and remove constraint (#5156) Removes resolved_by_alert field from Django state only. It will still be in db, since it's to expensive to delete it in prod. We remove this field to get rid of ON_DELETE=SET_NULL which causes terrible load from SQL queries. On top of that, we are removing FK to disable referral integrity checks, so alert updates will work. --------- Co-authored-by: Vadim Stepanov --- ...0061_alter_alertgroup_resolved_by_alert.py | 19 +++++++++++++++++++ engine/apps/alerts/models/alert_group.py | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 engine/apps/alerts/migrations/0061_alter_alertgroup_resolved_by_alert.py diff --git a/engine/apps/alerts/migrations/0061_alter_alertgroup_resolved_by_alert.py b/engine/apps/alerts/migrations/0061_alter_alertgroup_resolved_by_alert.py new file mode 100644 index 0000000000..bb1b21e322 --- /dev/null +++ b/engine/apps/alerts/migrations/0061_alter_alertgroup_resolved_by_alert.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.15 on 2024-10-10 11:02 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('alerts', '0060_relatedincident'), + ] + + operations = [ + migrations.AlterField( + model_name='alertgroup', + name='resolved_by_alert', + field=models.ForeignKey(db_constraint=False, default=None, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='resolved_alert_groups', to='alerts.alert'), + ), + ] diff --git a/engine/apps/alerts/models/alert_group.py b/engine/apps/alerts/models/alert_group.py index 7a7b4e193c..838e60887c 100644 --- a/engine/apps/alerts/models/alert_group.py +++ b/engine/apps/alerts/models/alert_group.py @@ -289,7 +289,8 @@ class AlertGroup(AlertGroupSlackRenderingMixin, EscalationSnapshotMixin, models. resolved_by_alert = models.ForeignKey( "alerts.Alert", - on_delete=models.SET_NULL, + on_delete=models.DO_NOTHING, + db_constraint=False, null=True, default=None, related_name="resolved_alert_groups",