Skip to content

Commit

Permalink
clean up email in username
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Nov 26, 2024
1 parent 8fe23d9 commit e712237
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lacommunaute/users/migrations/0004_run_management.py
Original file line number Diff line number Diff line change
@@ -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),
]

0 comments on commit e712237

Please sign in to comment.