Skip to content

Commit

Permalink
Merge pull request #236 from nautobot/u/gas-squash-migrations
Browse files Browse the repository at this point in the history
squash and fix 2.0 migrations
  • Loading branch information
bradh11 authored Oct 17, 2023
2 parents 4ab0f3e + d9c0a2d commit f9506c1
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("dcim", "0005_device_local_context_schema"),
("extras", "0013_default_fallback_value_computedfield"),
("nautobot_device_lifecycle_mgmt", "0003_service_contracts"),
]

replaces = [
("nautobot_device_lifecycle_mgmt", "0004_validated_software_m2m"),
("nautobot_device_lifecycle_mgmt", "0014_pre_nautobot_v2_migrations"),
("nautobot_device_lifecycle_mgmt", "0015_role_migration"),
("nautobot_device_lifecycle_mgmt", "0016_role_migration_cleanup"),
]

operations = [
# 0004_validated_software_m2m
migrations.AlterModelOptions(
name="softwarelcm",
options={
"ordering": ("device_platform", "version", "end_of_support", "release_date"),
"verbose_name": "Software",
},
),
migrations.AddField(
model_name="validatedsoftwarelcm",
name="device_roles",
field=models.ManyToManyField(
blank=True, related_name="_validatedsoftwarelcm_device_roles_+", to="extras.Role"
),
),
migrations.AddField(
model_name="validatedsoftwarelcm",
name="device_types",
field=models.ManyToManyField(
blank=True, related_name="_validatedsoftwarelcm_device_types_+", to="dcim.DeviceType"
),
),
migrations.AddField(
model_name="validatedsoftwarelcm",
name="devices",
field=models.ManyToManyField(blank=True, related_name="_validatedsoftwarelcm_devices_+", to="dcim.Device"),
),
migrations.AddField(
model_name="validatedsoftwarelcm",
name="inventory_items",
field=models.ManyToManyField(
blank=True, related_name="_validatedsoftwarelcm_inventory_items_+", to="dcim.InventoryItem"
),
),
migrations.AddField(
model_name="validatedsoftwarelcm",
name="object_tags",
field=models.ManyToManyField(
blank=True, related_name="_validatedsoftwarelcm_object_tags_+", to="extras.Tag"
),
),
migrations.AlterUniqueTogether(
name="validatedsoftwarelcm",
unique_together=set(),
),
migrations.RemoveField(
model_name="validatedsoftwarelcm",
name="assigned_to_content_type",
),
migrations.RemoveField(
model_name="validatedsoftwarelcm",
name="assigned_to_object_id",
),
]
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from django.db import migrations, models
import nautobot.core.models.fields


class Migration(migrations.Migration):
dependencies = [
("extras", "0062_collect_roles_from_related_apps_roles"),
("nautobot_device_lifecycle_mgmt", "0013_alter_softwareimagelcm_device_types"),
("nautobot_device_lifecycle_mgmt", "0004_validated_software_m2m"),
]

operations = [
Expand All @@ -21,109 +20,4 @@ class Migration(migrations.Migration):
old_name="device_roles",
new_name="legacy_roles",
),
migrations.AlterField(
model_name="contactlcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="contactlcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="contractlcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="contractlcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="cvelcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="cvelcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="devicesoftwarevalidationresult",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="devicesoftwarevalidationresult",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="hardwarelcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="hardwarelcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="inventoryitemsoftwarevalidationresult",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="inventoryitemsoftwarevalidationresult",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="providerlcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="softwareimagelcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="softwareimagelcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="softwarelcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="softwarelcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="validatedsoftwarelcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="validatedsoftwarelcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="vulnerabilitylcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="vulnerabilitylcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
]
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django.db import migrations
from django.db import connection, migrations


class Migration(migrations.Migration):
dependencies = [
("nautobot_device_lifecycle_mgmt", "0015_role_migration"),
]

run_before = [("dcim", "0031_remove_device_role_and_rack_role")]
nautobot_run_before = [("dcim", "0031_remove_device_role_and_rack_role")]

operations = [
migrations.RemoveField(
Expand All @@ -19,3 +19,18 @@ class Migration(migrations.Migration):
new_name="device_roles",
),
]

def __init__(self, name, app_label):
"""
Override the default __init__ method to conditionally set the run_before attribute based on whether
the first squashed migration has already been applied. This is necessary to ensure that the depdendency
graph generated by Django does not fail due to a circular dependency.
"""
super().__init__(name, app_label)
if self.nautobot_run_before:
recorder = migrations.recorder.MigrationRecorder(connection)
applied_migrations = recorder.applied_migrations()
if ("nautobot_device_onboarding", "0004_validated_software_m2m") in applied_migrations:
for migration in self.nautobot_run_before:
if migration not in applied_migrations:
self.run_before.append(migration)
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ def set_default_on_software_text_fields(apps, schema_editor):

class Migration(migrations.Migration):
dependencies = [
("nautobot_device_lifecycle_mgmt", "0016_role_migration_cleanup"),
("nautobot_device_lifecycle_mgmt", "0001_hardwarelcm"),
("nautobot_device_lifecycle_mgmt", "0002_softwarelcm"),
("nautobot_device_lifecycle_mgmt", "0003_service_contracts"),
("nautobot_device_lifecycle_mgmt", "0006_cvelcm_vulnerabilitylcm"),
]

operations = [
Expand Down
127 changes: 127 additions & 0 deletions nautobot_device_lifecycle_mgmt/migrations/0020_alter_created_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
from django.db import migrations, models

import nautobot.core.models.fields


class Migration(migrations.Migration):
dependencies = [
("nautobot_device_lifecycle_mgmt", "0001_hardwarelcm"),
("nautobot_device_lifecycle_mgmt", "0002_softwarelcm"),
("nautobot_device_lifecycle_mgmt", "0003_service_contracts"),
("nautobot_device_lifecycle_mgmt", "0005_software_reporting"),
("nautobot_device_lifecycle_mgmt", "0006_cvelcm_vulnerabilitylcm"),
("nautobot_device_lifecycle_mgmt", "0007_softwareimagelcm"),
# This migration does not actually depend on the below migrations but they are added here to
# prevent Django from failing to migrate due to multiple leaf nodes in the migration graph
("nautobot_device_lifecycle_mgmt", "0013_alter_softwareimagelcm_device_types"),
("nautobot_device_lifecycle_mgmt", "0016_role_migration_cleanup"),
("nautobot_device_lifecycle_mgmt", "0019_cve_and_contract_m2m_migration"),
]

operations = [
migrations.AlterField(
model_name="contactlcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="contactlcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="contractlcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="contractlcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="cvelcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="cvelcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="devicesoftwarevalidationresult",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="devicesoftwarevalidationresult",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="hardwarelcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="hardwarelcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="inventoryitemsoftwarevalidationresult",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="inventoryitemsoftwarevalidationresult",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="providerlcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="softwareimagelcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="softwareimagelcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="softwarelcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="softwarelcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="validatedsoftwarelcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="validatedsoftwarelcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
migrations.AlterField(
model_name="vulnerabilitylcm",
name="created",
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AlterField(
model_name="vulnerabilitylcm",
name="tags",
field=nautobot.core.models.fields.TagsField(through="extras.TaggedItem", to="extras.Tag"),
),
]

0 comments on commit f9506c1

Please sign in to comment.