mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-01 15:37:19 +00:00
perf: 删除一部分 system user
This commit is contained in:
53
apps/authentication/migrations/0012_auto_20220816_1629.py
Normal file
53
apps/authentication/migrations/0012_auto_20220816_1629.py
Normal file
@@ -0,0 +1,53 @@
|
||||
# Generated by Django 3.2.14 on 2022-08-16 08:29
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def migrate_system_user_to_accounts(apps, schema_editor):
|
||||
connection_token_model = apps.get_model("perms", "ConnectionToken")
|
||||
count = 0
|
||||
bulk_size = 10000
|
||||
|
||||
while True:
|
||||
connection_tokens = connection_token_model.objects \
|
||||
.prefect_related('system_users')[count:bulk_size]
|
||||
if not connection_tokens:
|
||||
break
|
||||
count += len(connection_tokens)
|
||||
updated = []
|
||||
for connection_token in connection_tokens:
|
||||
connection_token.account = connection_token.system_user.username
|
||||
updated.append(connection_token)
|
||||
connection_token_model.objects.bulk_update(updated, ['account'])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0011_auto_20220705_1940'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='connectiontoken',
|
||||
name='application',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='connectiontoken',
|
||||
name='application_display',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='connectiontoken',
|
||||
name='system_user_display',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='connectiontoken',
|
||||
name='account',
|
||||
field=models.CharField(default='', max_length=128, verbose_name='Account'),
|
||||
),
|
||||
migrations.RunPython(migrate_system_user_to_accounts),
|
||||
migrations.RemoveField(
|
||||
model_name='connectiontoken',
|
||||
name='system_user',
|
||||
)
|
||||
]
|
Reference in New Issue
Block a user