From 0615252e1555edc1f06dfa4ec057573573a4c826 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 14 Jul 2022 10:33:20 -0400 Subject: [PATCH] Add progress output to cable migration --- .../dcim/migrations/0158_populate_cable_terminations.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/netbox/dcim/migrations/0158_populate_cable_terminations.py b/netbox/dcim/migrations/0158_populate_cable_terminations.py index 82f8cd359..5836d24be 100644 --- a/netbox/dcim/migrations/0158_populate_cable_terminations.py +++ b/netbox/dcim/migrations/0158_populate_cable_terminations.py @@ -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)