Skip to content

Commit 6a3b692

Browse files
committed
Add migrations. Add public_user_uuid ID field and backfill user data.
1 parent 04f0143 commit 6a3b692

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from django.db import migrations, models
2+
3+
4+
class Migration(migrations.Migration):
5+
6+
dependencies = [
7+
("user", "0063_alter_training_status"),
8+
]
9+
10+
operations = [
11+
migrations.AddField(
12+
model_name="user",
13+
name="public_user_uuid",
14+
field=models.UUIDField(
15+
null=True,
16+
editable=False,
17+
db_index=True,
18+
help_text="Persistent, public identifier for user accounts.",
19+
),
20+
),
21+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 0065_backfill_public_user_uuid.py
2+
3+
from django.db import migrations
4+
import uuid
5+
6+
7+
def backfill_uuids(apps, schema_editor):
8+
User = apps.get_model("user", "User")
9+
for user in User.objects.filter(public_user_uuid__isnull=True):
10+
user.public_user_uuid = uuid.uuid4()
11+
user.save(update_fields=["public_user_uuid"])
12+
13+
14+
class Migration(migrations.Migration):
15+
16+
dependencies = [
17+
("user", "0064_user_public_user_uuid"),
18+
]
19+
20+
operations = [
21+
migrations.RunPython(backfill_uuids, reverse_code=migrations.RunPython.noop),
22+
]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 0066_enforce_public_user_uuid_constraints.py
2+
3+
from django.db import migrations, models
4+
import uuid
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("user", "0065_backfill_public_user_uuid"),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name="user",
16+
name="public_user_uuid",
17+
field=models.UUIDField(
18+
unique=True,
19+
default=uuid.uuid4,
20+
null=False,
21+
editable=False,
22+
db_index=True,
23+
help_text="Persistent, public identifier for user accounts.",
24+
),
25+
),
26+
]

0 commit comments

Comments
 (0)