diff --git a/lacommunaute/users/migrations/0004_run_management.py b/lacommunaute/users/migrations/0004_run_management.py new file mode 100644 index 000000000..c0d096bf9 --- /dev/null +++ b/lacommunaute/users/migrations/0004_run_management.py @@ -0,0 +1,25 @@ +# Generated by Django 5.0.9 on 2024-11-25 15:15 + +from django.db import migrations +from django.db.models import F + +from lacommunaute.users.models import User + + +def cleanup_email_in_username(apps, schema_editor): + users_to_migrate = User.objects.filter(username=F("email")) + + while batch_users := users_to_migrate[:100]: + for user in batch_users: + user.username = User.objects.generate_unique_username() + User.objects.bulk_update(batch_users, ["username"]) + + +class Migration(migrations.Migration): + dependencies = [ + ("users", "0003_alter_user_identity_provider"), + ] + + operations = [ + migrations.RunPython(cleanup_email_in_username), + ]