mirror of https://github.com/jumpserver/jumpserver
perf: 修改..
parent
9f927f9703
commit
5101aae5ae
|
@ -33,7 +33,6 @@ class Migration(migrations.Migration):
|
||||||
('created_by', models.CharField(blank=True, max_length=32, null=True, verbose_name='Created by')),
|
('created_by', models.CharField(blank=True, max_length=32, null=True, verbose_name='Created by')),
|
||||||
('date_created', models.DateTimeField(auto_now_add=True, null=True, verbose_name='Date created')),
|
('date_created', models.DateTimeField(auto_now_add=True, null=True, verbose_name='Date created')),
|
||||||
('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
||||||
('host', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='assets.host', related_name='device_info', verbose_name='Host')),
|
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
'verbose_name': 'DeviceInfo',
|
'verbose_name': 'DeviceInfo',
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Generated by Django 3.1.14 on 2022-04-02 08:27
|
# Generated by Django 3.1.14 on 2022-04-02 08:27
|
||||||
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.db import migrations
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
def migrate_hardware(apps, *args):
|
def migrate_hardware(apps, *args):
|
||||||
|
@ -23,10 +23,10 @@ def migrate_hardware(apps, *args):
|
||||||
asset_ids = [h.asset_ptr_id for h in hosts]
|
asset_ids = [h.asset_ptr_id for h in hosts]
|
||||||
assets = asset_model.objects.filter(id__in=asset_ids)
|
assets = asset_model.objects.filter(id__in=asset_ids)
|
||||||
asset_mapper = {a.id: a for a in assets}
|
asset_mapper = {a.id: a for a in assets}
|
||||||
|
|
||||||
if not hosts:
|
if not hosts:
|
||||||
break
|
break
|
||||||
|
|
||||||
hardware_list = []
|
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
hardware = hardware_model()
|
hardware = hardware_model()
|
||||||
asset = asset_mapper[host.asset_ptr_id]
|
asset = asset_mapper[host.asset_ptr_id]
|
||||||
|
@ -34,10 +34,9 @@ def migrate_hardware(apps, *args):
|
||||||
hardware.date_updated = timezone.now()
|
hardware.date_updated = timezone.now()
|
||||||
for name in fields:
|
for name in fields:
|
||||||
setattr(hardware, name, getattr(asset, name))
|
setattr(hardware, name, getattr(asset, name))
|
||||||
hardware_list.append(hardware)
|
hardware.save()
|
||||||
|
host.device_info = hardware
|
||||||
hardware_model.objects.bulk_create(hardware_list, ignore_conflicts=True)
|
host.save()
|
||||||
created += len(hardware_list)
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@ -47,5 +46,10 @@ class Migration(migrations.Migration):
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='host',
|
||||||
|
name='device_info',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=models.deletion.SET_NULL, to='assets.deviceinfo', verbose_name='Device info'),
|
||||||
|
),
|
||||||
migrations.RunPython(migrate_hardware)
|
migrations.RunPython(migrate_hardware)
|
||||||
]
|
]
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 3.1.14 on 2022-04-12 11:07
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('assets', '0097_auto_20220407_1726'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='deviceinfo',
|
||||||
|
name='host',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='host',
|
||||||
|
name='device_info',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='assets.deviceinfo', verbose_name='Device info'),
|
||||||
|
),
|
||||||
|
]
|
Loading…
Reference in New Issue