Make restored migrations 0003-0005 skip existing columns
Installations that applied 0003-0005 before they were removed from the repository still have the columns, but may no longer have the django_migrations rows. Running migrate then failed with DuplicateColumn on "provider". Use an AddField variant that only adds missing columns. Verified on NetBox 4.7.2 / PostgreSQL 17 / Python 3.13 with a fresh install, with all columns present but no migration rows, and with only some columns present. Bump version to 0.3.3. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
edba20a723
commit
a7d27336b6
7 files changed
+45
-10
No files matched your search
@@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.3.3
|
||||||
|
|
||||||
|
- Fixed `DuplicateColumn` (`column "provider" ... already exists`) when running migrations on
|
||||||
|
installations that still have the columns from migrations `0003`-`0005` but no longer have
|
||||||
|
them recorded in `django_migrations`. These migrations now only add columns that are missing.
|
||||||
|
|
||||||
## 0.3.2
|
## 0.3.2
|
||||||
|
|
||||||
- Raised `max_version` to `4.7.99`; verified against NetBox 4.7.2 (the plugin was skipped on 4.7.2 before).
|
- Raised `max_version` to `4.7.99`; verified against NetBox 4.7.2 (the plugin was skipped on 4.7.2 before).
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class VMwareImporterConfig(PluginConfig):
|
|||||||
name = "netbox_vmware_importer"
|
name = "netbox_vmware_importer"
|
||||||
verbose_name = "NetBox VMware Importer"
|
verbose_name = "NetBox VMware Importer"
|
||||||
description = "Synchronize VMware vSphere virtual machines into NetBox."
|
description = "Synchronize VMware vSphere virtual machines into NetBox."
|
||||||
version = "0.3.2"
|
version = "0.3.3"
|
||||||
author = "Codex & Claude"
|
author = "Codex & Claude"
|
||||||
base_url = "vmware-importer"
|
base_url = "vmware-importer"
|
||||||
min_version = "4.6.5"
|
min_version = "4.6.5"
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
from ._operations import AddFieldIfMissing
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
dependencies = [
|
dependencies = [
|
||||||
@@ -28,7 +30,7 @@ class Migration(migrations.Migration):
|
|||||||
to="virtualization.cluster",
|
to="virtualization.cluster",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
AddFieldIfMissing(
|
||||||
model_name="vcenterendpoint",
|
model_name="vcenterendpoint",
|
||||||
name="provider",
|
name="provider",
|
||||||
field=models.CharField(
|
field=models.CharField(
|
||||||
@@ -40,7 +42,7 @@ class Migration(migrations.Migration):
|
|||||||
max_length=30,
|
max_length=30,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
AddFieldIfMissing(
|
||||||
model_name="vcenterendpoint",
|
model_name="vcenterendpoint",
|
||||||
name="auth_method",
|
name="auth_method",
|
||||||
field=models.CharField(
|
field=models.CharField(
|
||||||
@@ -52,7 +54,7 @@ class Migration(migrations.Migration):
|
|||||||
max_length=30,
|
max_length=30,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
AddFieldIfMissing(
|
||||||
model_name="vcenterendpoint",
|
model_name="vcenterendpoint",
|
||||||
name="token_name",
|
name="token_name",
|
||||||
field=models.CharField(
|
field=models.CharField(
|
||||||
@@ -61,7 +63,7 @@ class Migration(migrations.Migration):
|
|||||||
max_length=100,
|
max_length=100,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
AddFieldIfMissing(
|
||||||
model_name="vcenterendpoint",
|
model_name="vcenterendpoint",
|
||||||
name="sync_lxc_containers",
|
name="sync_lxc_containers",
|
||||||
field=models.BooleanField(default=True, verbose_name="Sync Proxmox LXC containers"),
|
field=models.BooleanField(default=True, verbose_name="Sync Proxmox LXC containers"),
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import django.core.validators
|
import django.core.validators
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
from ._operations import AddFieldIfMissing
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
dependencies = [
|
dependencies = [
|
||||||
@@ -8,7 +10,7 @@ class Migration(migrations.Migration):
|
|||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AddField(
|
AddFieldIfMissing(
|
||||||
model_name="vcenterendpoint",
|
model_name="vcenterendpoint",
|
||||||
name="request_timeout_seconds",
|
name="request_timeout_seconds",
|
||||||
field=models.PositiveIntegerField(
|
field=models.PositiveIntegerField(
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import decimal
|
|||||||
import django.core.validators
|
import django.core.validators
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
from ._operations import AddFieldIfMissing
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
dependencies = [
|
dependencies = [
|
||||||
@@ -10,7 +12,7 @@ class Migration(migrations.Migration):
|
|||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AddField(
|
AddFieldIfMissing(
|
||||||
model_name="vcenterendpoint",
|
model_name="vcenterendpoint",
|
||||||
name="connect_timeout_seconds",
|
name="connect_timeout_seconds",
|
||||||
field=models.PositiveIntegerField(
|
field=models.PositiveIntegerField(
|
||||||
@@ -22,7 +24,7 @@ class Migration(migrations.Migration):
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
AddFieldIfMissing(
|
||||||
model_name="vcenterendpoint",
|
model_name="vcenterendpoint",
|
||||||
name="max_retries",
|
name="max_retries",
|
||||||
field=models.PositiveSmallIntegerField(
|
field=models.PositiveSmallIntegerField(
|
||||||
@@ -34,7 +36,7 @@ class Migration(migrations.Migration):
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
AddFieldIfMissing(
|
||||||
model_name="vcenterendpoint",
|
model_name="vcenterendpoint",
|
||||||
name="retry_backoff_seconds",
|
name="retry_backoff_seconds",
|
||||||
field=models.DecimalField(
|
field=models.DecimalField(
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class AddFieldIfMissing(migrations.AddField):
|
||||||
|
"""
|
||||||
|
AddField that leaves an already existing column alone.
|
||||||
|
|
||||||
|
Migrations 0003-0005 were temporarily removed from the repository. Installations that
|
||||||
|
applied them before that still have the columns, but may no longer have the matching
|
||||||
|
django_migrations rows, so a plain AddField would fail with DuplicateColumn.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
||||||
|
model = to_state.apps.get_model(app_label, self.model_name)
|
||||||
|
column = model._meta.get_field(self.name).column
|
||||||
|
connection = schema_editor.connection
|
||||||
|
with connection.cursor() as cursor:
|
||||||
|
existing = {
|
||||||
|
col.name for col in connection.introspection.get_table_description(cursor, model._meta.db_table)
|
||||||
|
}
|
||||||
|
if column in existing:
|
||||||
|
return
|
||||||
|
super().database_forwards(app_label, schema_editor, from_state, to_state)
|
||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "netbox-vmware-importer"
|
name = "netbox-vmware-importer"
|
||||||
version = "0.3.2"
|
version = "0.3.3"
|
||||||
description = "NetBox plugin to synchronize VMware vSphere virtual machines into NetBox."
|
description = "NetBox plugin to synchronize VMware vSphere virtual machines into NetBox."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
|
|||||||
Reference in new issue
Block a user