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

Squash migrations / fix migrations for nautobot 2.0 #113

Merged
merged 5 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 0 additions & 4 deletions nautobot_device_onboarding/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ class Migration(migrations.Migration):
("dcim", "0004_initial_part_4"),
]

run_before = [
("dcim", "0028_alter_device_and_rack_role_add_new_role"),
]

operations = [
migrations.CreateModel(
name="OnboardingTask",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Migration(migrations.Migration):
dependencies = [
("nautobot_device_onboarding", "0003_onboardingtask_label"),
("nautobot_device_onboarding", "0001_initial"),
("dcim", "0029_device_and_rack_roles_data_migrations"),
]

Expand Down
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_onboarding", "0004_migrate_to_extras_role_part_2"),
]

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

Expand All @@ -21,3 +21,13 @@ class Migration(migrations.Migration):
new_name="role",
),
]

def __init__(self, name, app_label):
super().__init__(name, app_label)
if self.nautobot_run_before:
recorder = migrations.recorder.MigrationRecorder(connection)
applied_migrations = recorder.applied_migrations()
if ("nautobot_device_onboarding", "0001_initial") 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
@@ -1,12 +1,12 @@
from django.db import migrations
from django.db import connection, migrations


class Migration(migrations.Migration):
dependencies = [
("nautobot_device_onboarding", "0005_migrate_site_to_location_part_2"),
]

run_before = [
nautobot_run_before = [
("dcim", "0040_remove_region_and_site"),
]

Expand All @@ -16,3 +16,13 @@ class Migration(migrations.Migration):
name="site",
)
]

def __init__(self, name, app_label):
super().__init__(name, app_label)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind adding a docstring or comment explaining this and the similar logic in the previous file for future reference?

if self.nautobot_run_before:
recorder = migrations.recorder.MigrationRecorder(connection)
applied_migrations = recorder.applied_migrations()
if ("nautobot_device_onboarding", "0001_initial") 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 @@ -19,8 +19,4 @@ class Migration(migrations.Migration):
name="status",
field=models.CharField(blank=True, default="", max_length=255),
),
migrations.AlterUniqueTogether(
name="onboardingtask",
unique_together={("label", "ip_address")},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("nautobot_device_onboarding", "0003_onboardingtask_label"),
("nautobot_device_onboarding", "0007_alter_onboardingtask_ip_address"),
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly add a comment here explaining that this is needed to bring the 01->02->03 and the 01->04->05->06->07 branches of the migration tree back together?


operations = [
migrations.AlterModelOptions(
name="onboardingtask",
options={
"ordering": ("label",),
},
),
migrations.AlterUniqueTogether(
name="onboardingtask",
unique_together={("label", "ip_address")},
),
]
97 changes: 97 additions & 0 deletions nautobot_device_onboarding/migrations/0101_squashed.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is numbering this one as 0101 confusing? Can we number it as something like 0001_0004_0005_0006 instead and would that be clearer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be concerned about having another 0001_ prefixed file that would be adjacent to 0001_initial, but I agree with the sentiment of naming the migration more verbosely.

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Generated by Django 3.2.21 on 2023-10-13 16:17

import uuid

from django.db import migrations, models
import django.db.models.deletion

import nautobot_device_onboarding.models


class Migration(migrations.Migration):
initial = True

replaces = [
("nautobot_device_onboarding", "0001_initial"),
("nautobot_device_onboarding", "0004_migrate_to_extras_role_part_1"),
("nautobot_device_onboarding", "0004_migrate_to_extras_role_part_2"),
("nautobot_device_onboarding", "0004_migrate_to_extras_role_part_3"),
("nautobot_device_onboarding", "0005_migrate_site_to_location_part_1"),
("nautobot_device_onboarding", "0005_migrate_site_to_location_part_2"),
("nautobot_device_onboarding", "0005_migrate_site_to_location_part_3"),
("nautobot_device_onboarding", "0006_update_model_fields_part_1"),
("nautobot_device_onboarding", "0006_update_model_fields_part_2"),
("nautobot_device_onboarding", "0006_update_model_fields_part_3"),
]

dependencies = [
("dcim", "0049_remove_slugs_and_change_device_primary_ip_fields"),
("extras", "0098_rename_data_jobresult_result"),
]

operations = [
migrations.CreateModel(
name="OnboardingDevice",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True
),
),
("enabled", models.BooleanField(default=True)),
("device", models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to="dcim.device")),
],
options={
"abstract": False,
},
),
migrations.CreateModel(
name="OnboardingTask",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True
),
),
("created", models.DateTimeField(auto_now_add=True, null=True)),
("last_updated", models.DateTimeField(auto_now=True, null=True)),
("ip_address", models.CharField(max_length=255)),
("device_type", models.CharField(blank=True, default="", max_length=255)),
("status", models.CharField(blank=True, default="", max_length=255)),
("failed_reason", models.CharField(blank=True, default="", max_length=255)),
("message", models.CharField(blank=True, max_length=511)),
("port", models.PositiveSmallIntegerField(default=22)),
("timeout", models.PositiveSmallIntegerField(default=30)),
(
"created_device",
models.ForeignKey(
blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to="dcim.device"
),
),
(
"location",
models.ForeignKey(
blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to="dcim.location"
),
),
(
"platform",
models.ForeignKey(
blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to="dcim.platform"
),
),
(
"role",
nautobot_device_onboarding.models.DeviceLimitedRoleField(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="onboarding_tasks",
to="extras.role",
),
),
],
),
]
Loading