# Generated by Django 5.2.13 on 2026-05-06 15:45

from django.db import migrations
from django.db.models import F


def remove_cross_event_scheduled_mails(apps, schema_editor):
    Rule = apps.get_model("sendmail", "Rule")
    ScheduledMail = apps.get_model("sendmail", "ScheduledMail")
    ScheduledMail.objects.filter(subevent__isnull=False).exclude(subevent__event=F('rule__event')).delete()
    Rule.objects.filter(subevent__isnull=False).exclude(subevent__event=F('event')).delete()

class Migration(migrations.Migration):

    replaces = [('sendmail', '0011_remove_cross_event_scheduled_mails'), ('sendmail', '0012_remove_cross_event_scheduled_mails')]

    dependencies = [
        ('sendmail', '0010_auto_20250801_1342'),
    ]

    operations = [
        migrations.RunPython(
            code=remove_cross_event_scheduled_mails,
        ),
    ]
