Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CustomField Migration #595

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/411.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed imports in CustomFields migration that was causing installation issues.
16 changes: 12 additions & 4 deletions nautobot_ssot/migrations/0007_replace_dashed_custom_fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from django.db import migrations
from nautobot.dcim.models import Device, DeviceType, Interface, Location, Manufacturer
from nautobot.extras.models import Role
from nautobot.ipam.models import VLAN, IPAddress

CF_KEY_CHANGE_MAP = {
"ssot_synced_to_servicenow": "ssot-synced-to-servicenow",
Expand All @@ -12,6 +9,7 @@


def replace_dashed_custom_fields(apps, schema_editor):
"""Replace dashes in CustomField keys with underscore."""
CustomField = apps.get_model("extras", "customfield")

for new_key, old_key in CF_KEY_CHANGE_MAP.items():
Expand All @@ -23,7 +21,17 @@ def replace_dashed_custom_fields(apps, schema_editor):
custom_field.key = new_key
custom_field.save()

for model in [Device, DeviceType, Interface, Manufacturer, Location, VLAN, Role, IPAddress]:
for app, model in [
("dcim", "Device"),
("dcim", "DeviceType"),
("dcim", "Interface"),
("dcim", "Manufacturer"),
("dcim", "Location"),
("ipam", "VLAN"),
("extras", "Role"),
("ipam", "IPAddress"),
]:
model = apps.get_model(app, model)
cf_list = []
for instance in model.objects.all():
for new_cf, old_cf in CF_KEY_CHANGE_MAP.items():
Expand Down