# Generated by Django 4.2.10 on 2024-02-21 18:28

from django.db import migrations, models


def migrate_integration_filter_to_filtered_integrations(apps, schema_editor):
    AlertReceiveChannel = apps.get_model("alerts", "AlertReceiveChannel")
    Webhook = apps.get_model("webhooks", "Webhook")

    to_migrate = Webhook.objects.filter(integration_filter__isnull=False)
    for w in to_migrate:
        w.filtered_integrations.set(
            AlertReceiveChannel.objects.filter(public_primary_key__in=w.integration_filter)
        )


class Migration(migrations.Migration):

    dependencies = [
        ('alerts', '0045_escalationpolicy_notify_to_team_members_and_more'),
        ('webhooks', '0013_alter_webhook_trigger_type_and_more'),
    ]

    operations = [
        migrations.AddField(
            model_name='webhook',
            name='filtered_integrations',
            field=models.ManyToManyField(related_name='webhooks', to='alerts.alertreceivechannel'),
        ),
        migrations.RunPython(migrate_integration_filter_to_filtered_integrations, migrations.RunPython.noop),
    ]
