Fix problem with duplicate usernames

This commit is contained in:
Lorenz Padberg 2024-02-07 14:58:06 +01:00
parent ce7ab55cba
commit 216f448137
3 changed files with 14 additions and 8 deletions

View File

@ -12,17 +12,23 @@ class Command(BaseCommand):
self.stdout.write("If so, type \"YES\"") self.stdout.write("If so, type \"YES\"")
result = input() result = input()
user_model = get_user_model()
if result == 'YES': if result == 'YES':
users = get_user_model().objects.all() users = user_model.objects.all().order_by('email')
with ThreadPoolExecutor(max_workers=10) as executor: with ThreadPoolExecutor(max_workers=5) as executor:
executor.map(process_user, users) executor.map(process_user, users)
def process_user(usr): def process_user(usr):
# replace domain with skillbox.ch # replace domain with id.skillbox.ch,to ensure unique emails
usr.email = usr.email.split('@')[0] + '@skillbox.ch' usr.email = usr.email.split('@')[0] + f'@skillbox.ch'
user_model = get_user_model()
if user_model.objects.filter(email=usr.email).exists():
usr.email = usr.email.split('@')[0] + f'@{usr.id}.skillbox.ch'
usr.username = usr.email usr.username = usr.email
print(usr.email) print(usr.email)

View File

@ -4,9 +4,9 @@ python manage.py reset_all_passwords
pg_dump -Fc --no-acl -h localhost -U skillbox skillbox > latest-anonymized.dump pg_dump -Fc --no-acl -h localhost -U skillbox skillbox > latest-anonymized.dump
python manage.py migrate_objectives_to_content python manage.py migrate_objectives_to_content
pg_dump -Fc --no-acl -h localhost -U skillbox skillbox > latest-migrated-objectives.dump pg_dump -Fc --no-acl -h localhost -U skillbox skillbox > latest-migrated-objectives.dump
#python manage.py migrate_objective_snapshots python manage.py migrate_objective_snapshots
#pg_dump -Fc --no-acl -h localhost -U skillbox skillbox > latest-migrated-objectives-and-snapshots.dump pg_dump -Fc --no-acl -h localhost -U skillbox skillbox > latest-migrated-objectives-and-snapshots.dump
# Use this command to restore the database from the dump: #Use this command to restore the database from the dump:
#pg_restore --verbose --clean --no-acl --no-owner -h localhost -U skillbox -d skillbox latest-migrated-objectives.dump #pg_restore --verbose --clean --no-acl --no-owner -h localhost -U skillbox -d skillbox latest-migrated-objectives.dump