diff --git a/apps/assets/migrations/0092_hardware.py b/apps/assets/migrations/0092_hardware.py index 55487cc22..26d026640 100644 --- a/apps/assets/migrations/0092_hardware.py +++ b/apps/assets/migrations/0092_hardware.py @@ -33,7 +33,6 @@ class Migration(migrations.Migration): ('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_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={ 'verbose_name': 'DeviceInfo', diff --git a/apps/assets/migrations/0093_auto_20220403_1627.py b/apps/assets/migrations/0093_auto_20220403_1627.py index 497a56c6c..9aa3be14d 100644 --- a/apps/assets/migrations/0093_auto_20220403_1627.py +++ b/apps/assets/migrations/0093_auto_20220403_1627.py @@ -1,7 +1,7 @@ # Generated by Django 3.1.14 on 2022-04-02 08:27 from django.utils import timezone -from django.db import migrations +from django.db import migrations, models def migrate_hardware(apps, *args): @@ -23,10 +23,10 @@ def migrate_hardware(apps, *args): asset_ids = [h.asset_ptr_id for h in hosts] assets = asset_model.objects.filter(id__in=asset_ids) asset_mapper = {a.id: a for a in assets} + if not hosts: break - hardware_list = [] for host in hosts: hardware = hardware_model() asset = asset_mapper[host.asset_ptr_id] @@ -34,10 +34,9 @@ def migrate_hardware(apps, *args): hardware.date_updated = timezone.now() for name in fields: setattr(hardware, name, getattr(asset, name)) - hardware_list.append(hardware) - - hardware_model.objects.bulk_create(hardware_list, ignore_conflicts=True) - created += len(hardware_list) + hardware.save() + host.device_info = hardware + host.save() class Migration(migrations.Migration): @@ -47,5 +46,10 @@ class Migration(migrations.Migration): ] 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) ] diff --git a/apps/assets/migrations/0098_auto_20220412_1907.py b/apps/assets/migrations/0098_auto_20220412_1907.py new file mode 100644 index 000000000..c12bbd644 --- /dev/null +++ b/apps/assets/migrations/0098_auto_20220412_1907.py @@ -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'), + ), + ]