# Generated by Django 4.2.11 on 2024-04-02 13:41

from django.db import migrations
import django_migration_linter as linter

from apps.alerts.models import EscalationPolicy


def delete_orphaned_custom_button_escalation_policies(apps, schema_editor):
    """
    See this conversation for more context behind this
    https://raintank-corp.slack.com/archives/C025VMT6SPK/p1711991400490289
    """
    EscalationPolicies = apps.get_model("alerts", "EscalationPolicy")
    EscalationPolicies.objects.filter(
        step=EscalationPolicy._DEPRECATED_STEP_TRIGGER_CUSTOM_BUTTON,
        custom_webhook=None,
    ).delete()


class Migration(migrations.Migration):

    dependencies = [
        ('webhooks', '0015_webhook_is_from_connected_integration'),
    ]

    operations = [
        linter.IgnoreMigration(), # removing orphaned escalation policies should be fine, no way to revert this
        migrations.RunPython(delete_orphaned_custom_button_escalation_policies)
    ]
