mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 08:38:16 -06:00
Clean up migration
This commit is contained in:
parent
aaa4992280
commit
aa8475cdc4
@ -6,19 +6,17 @@ from django.db.backends.postgresql.psycopg_any import NumericRange
|
|||||||
import ipam.models.vlans
|
import ipam.models.vlans
|
||||||
|
|
||||||
|
|
||||||
def move_min_max(apps, schema_editor):
|
def set_vid_ranges(apps, schema_editor):
|
||||||
|
"""
|
||||||
|
Convert the min_vid & max_vid fields to a range in the new vid_ranges ArrayField.
|
||||||
|
"""
|
||||||
VLANGroup = apps.get_model('ipam', 'VLANGroup')
|
VLANGroup = apps.get_model('ipam', 'VLANGroup')
|
||||||
for group in VLANGroup.objects.all():
|
for group in VLANGroup.objects.all():
|
||||||
if group.min_vid or group.max_vid:
|
group.vid_ranges = [
|
||||||
group.vid_ranges = [
|
NumericRange(group.min_vid, group.max_vid, bounds='[]')
|
||||||
NumericRange(group.min_vid, group.max_vid, bounds='[]')
|
]
|
||||||
]
|
group._total_vlan_ids = group.max_vid - group.min_vid + 1
|
||||||
|
group.save()
|
||||||
group._total_vlan_ids = 0
|
|
||||||
for vlan_range in group.vid_ranges:
|
|
||||||
group._total_vlan_ids += int(vlan_range.upper) - int(vlan_range.lower) + 1
|
|
||||||
|
|
||||||
group.save()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
@ -43,7 +41,7 @@ class Migration(migrations.Migration):
|
|||||||
field=models.PositiveBigIntegerField(default=4094),
|
field=models.PositiveBigIntegerField(default=4094),
|
||||||
),
|
),
|
||||||
migrations.RunPython(
|
migrations.RunPython(
|
||||||
code=move_min_max,
|
code=set_vid_ranges,
|
||||||
reverse_code=migrations.RunPython.noop
|
reverse_code=migrations.RunPython.noop
|
||||||
),
|
),
|
||||||
migrations.RemoveField(
|
migrations.RemoveField(
|
||||||
|
Loading…
Reference in New Issue
Block a user