1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

13745 device type migration (#13747)

* 13745 update migrations to use batch_size

* 13745 update migrations to use subquery update

* 13745 refactor and update other counter migrations
This commit is contained in:
Arthur Hanson
2023-09-18 06:59:26 -07:00
committed by GitHub
parent 3d1f668235
commit b0541be107
6 changed files with 47 additions and 104 deletions

View File

@@ -2,17 +2,13 @@ from django.db import migrations
from django.db.models import Count
import utilities.fields
from utilities.counters import update_counts
def populate_virtualmachine_counts(apps, schema_editor):
VirtualMachine = apps.get_model('virtualization', 'VirtualMachine')
vms = VirtualMachine.objects.annotate(_interface_count=Count('interfaces', distinct=True))
for vm in vms:
vm.interface_count = vm._interface_count
VirtualMachine.objects.bulk_update(vms, ['interface_count'], batch_size=100)
update_counts(VirtualMachine, 'interface_count', 'interfaces')
class Migration(migrations.Migration):