Fix problem with duplicate usernames
This commit is contained in:
parent
ce7ab55cba
commit
216f448137
|
|
@ -149,7 +149,7 @@ def migrate_snapshots():
|
|||
default_content_block = get_default_content_block(objective_group_snapshot, module)
|
||||
if default_content_block:
|
||||
print(f"Default content block: {default_content_block.title}")
|
||||
snapshot.hidden_content_blocks.add(default_content_block.id)
|
||||
snapshot.hidden_content_blocks.add(default_content_block.id)
|
||||
|
||||
if list(visible_objectives_by_ids.values()):
|
||||
objectives = list(visible_objectives_by_ids.values())[0]
|
||||
|
|
|
|||
|
|
@ -12,17 +12,23 @@ class Command(BaseCommand):
|
|||
self.stdout.write("If so, type \"YES\"")
|
||||
|
||||
result = input()
|
||||
user_model = get_user_model()
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def process_user(usr):
|
||||
# replace domain with skillbox.ch
|
||||
usr.email = usr.email.split('@')[0] + '@skillbox.ch'
|
||||
# replace domain with id.skillbox.ch,to ensure unique emails
|
||||
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
|
||||
print(usr.email)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ python manage.py reset_all_passwords
|
|||
pg_dump -Fc --no-acl -h localhost -U skillbox skillbox > latest-anonymized.dump
|
||||
python manage.py migrate_objectives_to_content
|
||||
pg_dump -Fc --no-acl -h localhost -U skillbox skillbox > latest-migrated-objectives.dump
|
||||
#python manage.py migrate_objective_snapshots
|
||||
#pg_dump -Fc --no-acl -h localhost -U skillbox skillbox > latest-migrated-objectives-and-snapshots.dump
|
||||
python manage.py migrate_objective_snapshots
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue