mirror of https://github.com/jumpserver/jumpserver
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
# Generated by Django 3.2.14 on 2022-08-17 05:46
|
|
|
|
from django.db import migrations, models
|
|
|
|
|
|
def migrate_run_system_user_to_account(apps, schema_editor):
|
|
execution_model = apps.get_model('ops', 'CommandExecution')
|
|
count = 0
|
|
bulk_size = 1000
|
|
|
|
while True:
|
|
executions = execution_model.objects.all().prefetch_related('run_as')[count:bulk_size]
|
|
if not executions:
|
|
break
|
|
count += len(executions)
|
|
updated = []
|
|
for obj in executions:
|
|
run_as = obj.run_as
|
|
if not run_as:
|
|
continue
|
|
obj.account = run_as.username
|
|
updated.append(obj)
|
|
execution_model.objects.bulk_update(updated, ['account'])
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('ops', '0021_auto_20211130_1037'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RemoveField(
|
|
model_name='adhoc',
|
|
name='run_system_user',
|
|
),
|
|
migrations.AddField(
|
|
model_name='commandexecution',
|
|
name='account',
|
|
field=models.CharField(default='', max_length=128, verbose_name='account'),
|
|
),
|
|
migrations.RunPython(migrate_run_system_user_to_account),
|
|
migrations.RemoveField(
|
|
model_name='commandexecution',
|
|
name='run_as',
|
|
),
|
|
]
|