-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path0031_app_uid_alter_workspace_uid.py
More file actions
36 lines (28 loc) · 1.1 KB
/
Copy path0031_app_uid_alter_workspace_uid.py
File metadata and controls
36 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Generated by Django 5.2.14 on 2026-05-26 01:01
from django.db import migrations, models
def set_app_uids(apps, schema_editor):
App = apps.get_model('api', 'App')
# 模拟 get_next_uid 的类似逻辑,或者是直接调用,但需要防范现有库里全是 null 导致的 TypeError
# 使用 id 排序来保证赋值的确定性
uid = App.objects.aggregate(models.Max('uid'))['uid__max'] or 0
for app in App.objects.filter(uid__isnull=True).order_by('created'):
uid += 1
app.uid = uid
app.save(update_fields=['uid'])
class Migration(migrations.Migration):
dependencies = [
('api', '0030_delete_blocklist_remove_app_suspended_state'),
]
operations = [
migrations.AddField(
model_name='app',
name='uid',
field=models.PositiveIntegerField(blank=True, null=True),
),
migrations.RunPython(set_app_uids, migrations.RunPython.noop),
migrations.AlterField(
model_name='app',
name='uid',
field=models.PositiveIntegerField(unique=True),
),
]