Skip to content

Commit 02a0947

Browse files
feat(user): switch primary key to UUID
BREAKING CHANGE: changes User.id from integer to UUID.
1 parent 2899373 commit 02a0947

File tree

3 files changed

+46
-59
lines changed

3 files changed

+46
-59
lines changed
Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# Generated by Django 5.2b1 on 2025-02-28 17:01
1+
# Generated by Django 5.2 on 2025-05-01 19:23
22

3+
import uuid
34
from django.db import migrations, models
45

56

@@ -8,70 +9,66 @@ class Migration(migrations.Migration):
89
initial = True
910

1011
dependencies = [
11-
('auth', '0012_alter_user_first_name_max_length'),
12+
("auth", "0012_alter_user_first_name_max_length"),
1213
]
1314

1415
operations = [
1516
migrations.CreateModel(
16-
name='User',
17+
name="User",
1718
fields=[
19+
("password", models.CharField(max_length=128, verbose_name="password")),
1820
(
19-
'id',
20-
models.BigAutoField(
21-
auto_created=True,
22-
primary_key=True,
23-
serialize=False,
24-
verbose_name='ID',
25-
),
26-
),
27-
(
28-
'password',
29-
models.CharField(max_length=128, verbose_name='password'),
30-
),
31-
(
32-
'is_superuser',
21+
"is_superuser",
3322
models.BooleanField(
3423
default=False,
35-
help_text='Designates that this user has all permissions without explicitly assigning them.',
36-
verbose_name='superuser status',
24+
help_text="Designates that this user has all permissions without explicitly assigning them.",
25+
verbose_name="superuser status",
3726
),
3827
),
39-
('email', models.EmailField(max_length=120, unique=True)),
40-
('name', models.CharField(max_length=100)),
41-
('surname', models.CharField(max_length=120)),
4228
(
43-
'avatar_url',
44-
models.URLField(blank=True, max_length=350, null=True),
29+
"id",
30+
models.UUIDField(
31+
default=uuid.uuid4,
32+
editable=False,
33+
primary_key=True,
34+
serialize=False,
35+
verbose_name="UUID",
36+
),
4537
),
46-
('other', models.JSONField(default=dict)),
47-
('is_active', models.BooleanField(default=True)),
48-
('is_staff', models.BooleanField(default=False)),
49-
('last_login', models.DateTimeField(blank=True, null=True)),
38+
("email", models.EmailField(max_length=120, unique=True)),
39+
("name", models.CharField(max_length=100)),
40+
("surname", models.CharField(max_length=120)),
41+
("avatar_url", models.URLField(blank=True, max_length=350, null=True)),
42+
("other", models.JSONField(default=dict)),
43+
("token_version", models.IntegerField(default=0)),
44+
("is_active", models.BooleanField(default=True)),
45+
("is_staff", models.BooleanField(default=False)),
46+
("last_login", models.DateTimeField(blank=True, null=True)),
5047
(
51-
'groups',
48+
"groups",
5249
models.ManyToManyField(
5350
blank=True,
54-
help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.',
55-
related_name='user_set',
56-
related_query_name='user',
57-
to='auth.group',
58-
verbose_name='groups',
51+
help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
52+
related_name="user_set",
53+
related_query_name="user",
54+
to="auth.group",
55+
verbose_name="groups",
5956
),
6057
),
6158
(
62-
'user_permissions',
59+
"user_permissions",
6360
models.ManyToManyField(
6461
blank=True,
65-
help_text='Specific permissions for this user.',
66-
related_name='user_set',
67-
related_query_name='user',
68-
to='auth.permission',
69-
verbose_name='user permissions',
62+
help_text="Specific permissions for this user.",
63+
related_name="user_set",
64+
related_query_name="user",
65+
to="auth.permission",
66+
verbose_name="user permissions",
7067
),
7168
),
7269
],
7370
options={
74-
'abstract': False,
71+
"abstract": False,
7572
},
7673
),
7774
]

promo_code/user/migrations/0002_user_token_version.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

promo_code/user/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import uuid
2+
13
import django.contrib.auth.models
24
import django.db.models
35
import django.utils.timezone
@@ -38,6 +40,12 @@ class User(
3840
django.contrib.auth.models.AbstractBaseUser,
3941
django.contrib.auth.models.PermissionsMixin,
4042
):
43+
id = django.db.models.UUIDField(
44+
'UUID',
45+
primary_key=True,
46+
default=uuid.uuid4,
47+
editable=False,
48+
)
4149
email = django.db.models.EmailField(
4250
unique=True,
4351
max_length=user.constants.EMAIL_MAX_LENGTH,

0 commit comments

Comments
 (0)