diff --git a/server/books/management/commands/migrate_objective_snapshots.py b/server/books/management/commands/migrate_objective_snapshots.py index 5f053bd5..ad3e3f97 100644 --- a/server/books/management/commands/migrate_objective_snapshots.py +++ b/server/books/management/commands/migrate_objective_snapshots.py @@ -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] diff --git a/server/core/management/commands/reset_all_passwords.py b/server/core/management/commands/reset_all_passwords.py index 26557519..f198fdc4 100644 --- a/server/core/management/commands/reset_all_passwords.py +++ b/server/core/management/commands/reset_all_passwords.py @@ -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) diff --git a/server/test_objectives_migrations.sh b/server/test_objectives_migrations.sh index a206a701..6a24a1d8 100755 --- a/server/test_objectives_migrations.sh +++ b/server/test_objectives_migrations.sh @@ -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