Replace global IntegerKeyValueSetting with per-view CatalogZone model

Track the catalog zone SOA serial per view instead of a single global value.
The new CatalogZone model has a 1:1 FK to netbox_dns.models.View and its own
soa_serial field; each view's catalog zone now increments independently. The
existing global serial is preserved during migration by copying it into every
view's new CatalogZone row.

Change CatalogZoneMemberIdentifier.name from globally unique to unique per
catalog zone (UniqueConstraint(name, catalog_zone)) and add a catalog_zone FK
to enforce it.

Remove the dns-settings management command, which was a generic interface over
the now-removed IntegerKeyValueSetting model.

Increment both catalog zone serials when a zone moves between views: the old
view's catalog zone loses a member and the new view's gains one, so both must
be bumped. Also refresh the member identifier's catalog_zone FK on a view move
so it does not go stale. The pre_save handler now captures _old_view_id and the
post_save handler detects view changes, increments the old view's serial inside
on_commit (before the new view's), and re-creates the identifier.

AI generated, code manually verified.
This commit is contained in:
sven committed 2026-08-17 10:02:59 +02:00
1 parent 4ad110ca53
commit 9f5e40ae48
17 files changed
+429 -240

No files matched your search

+9 -7
View File
@@ -12,7 +12,7 @@ from django.db import close_old_connections, OperationalError
from netbox.jobs import JobRunner
from netbox_dns.models import View, Zone, Record
from netbox_dns_bridge.utils import get_logger
from netbox_dns_bridge.models import SeenTransferClients, IntegerKeyValueSetting
from netbox_dns_bridge.models import SeenTransferClients, CatalogZone
LOGGER = get_logger(__name__)
SETTINGS = settings.PLUGINS_CONFIG.get("netbox_dns_bridge", {})
@@ -51,9 +51,12 @@ class SendClientDNSNotify(JobRunner):
view_name = kwargs["view_name"]
try:
catz_serial = IntegerKeyValueSetting.objects.get(
key="catalog-zone-soa-serial"
).value
view = View.objects.get(name=view_name)
try:
catz_serial = view.catalog_zone.soa_serial
except CatalogZone.DoesNotExist as e:
LOGGER.error(f"Failed to get catalog zone serial: {e}")
return
zones = [
(kwargs["zone_name"], kwargs["soa_serial"]),
@@ -61,7 +64,6 @@ class SendClientDNSNotify(JobRunner):
(f"{view_name}.catz", catz_serial),
]
view = View.objects.get(name=view_name)
tsig_key = _load_tsig_key(view_name)
cutoff_hours = SETTINGS.get("notify_client_alive_threshold_hours", 24)
seen_cutoff = timezone.now() - timezone.timedelta(hours=cutoff_hours)
@@ -103,8 +105,8 @@ class SendClientDNSNotify(JobRunner):
f" {view_name}/{zone_name} {soa_serial}: {e}"
)
except IntegerKeyValueSetting.DoesNotExist as e:
LOGGER.error(f"Failed to get catalog zone serial: {e}")
except View.DoesNotExist as e:
LOGGER.error(f"Failed to get view for NOTIFY: {e}")
except OperationalError as e:
LOGGER.error(f"NOTIFY failed due to unexpected error: {e}")