mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
Add progress output to cable migration
This commit is contained in:
parent
be00d1f3c6
commit
0615252e15
@ -1,3 +1,5 @@
|
||||
import sys
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
@ -42,6 +44,7 @@ def populate_cable_terminations(apps, schema_editor):
|
||||
|
||||
# Queue CableTerminations to be created
|
||||
cable_terminations = []
|
||||
cable_count = cables.count()
|
||||
for i, cable in enumerate(cables, start=1):
|
||||
for cable_end in ('a', 'b'):
|
||||
# We must manually instantiate the termination object, because GFK fields are not
|
||||
@ -58,6 +61,12 @@ def populate_cable_terminations(apps, schema_editor):
|
||||
**cache_related_objects(termination)
|
||||
))
|
||||
|
||||
# Output progress occasionally
|
||||
if 'test' not in sys.argv and not i % 100:
|
||||
progress = float(i) * 100 / cable_count
|
||||
sys.stdout.write(f"\r Updated {i}/{cable_count} cables ({progress:.2f}%)")
|
||||
sys.stdout.flush()
|
||||
|
||||
# Bulk create the termination objects
|
||||
CableTermination.objects.bulk_create(cable_terminations, batch_size=100)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user