"""FRREP-UR005 — grandfather existing active accounts as email-verified.

Login now blocks unverified accounts. Before this change, ``email_verified``
was informational only — legacy/migrated accounts (Moodle import, etc.) and
most existing self-registrations never went through a real verification
step, so retroactively enforcing it would lock out the majority of the
existing user base with no way to receive a fresh link (the accounts predate
this gate entirely). Backfill once; new accounts follow the enforced flow.
"""
from django.db import migrations


def backfill_verified(apps, schema_editor):
    CustomUser = apps.get_model("core", "CustomUser")
    CustomUser.objects.filter(is_active=True, email_verified=False).update(email_verified=True)


def noop(apps, schema_editor):
    pass


class Migration(migrations.Migration):

    dependencies = [
        ("core", "0054_alter_notification_verb_and_more"),
    ]

    operations = [
        migrations.RunPython(backfill_verified, noop),
    ]
