-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from edx/varshamenon4/add-anonymous-user-id-wi…
…th-migration feat: generate anonymous_user_id field in User model
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
edx_exams/apps/core/migrations/0011_user_anonymous_user_id.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by Django 3.2.15 on 2022-09-29 20:54 | ||
|
||
from django.db import migrations, models | ||
import uuid | ||
|
||
|
||
def create_anonymous_user_ids(apps, schema_editor): | ||
User = apps.get_model('core', 'User') | ||
users = User.objects.all() | ||
for user in users: | ||
user.anonymous_user_id = uuid.uuid4() | ||
user.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0010_remove_user_anonymous_user_id'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='user', | ||
name='anonymous_user_id', | ||
field=models.UUIDField(default=uuid.uuid4, null=True), | ||
), | ||
migrations.RunPython(create_anonymous_user_ids), | ||
migrations.AlterField( | ||
model_name='user', | ||
name='anonymous_user_id', | ||
field=models.UUIDField(default=uuid.uuid4, editable=False, unique=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters