diff --git a/images/netbox/local_settings.py b/images/netbox/local_settings.py index 764b580..2b14712 100644 --- a/images/netbox/local_settings.py +++ b/images/netbox/local_settings.py @@ -2,23 +2,15 @@ # NetBox Local Settings for netbox-branching plugin # ============================================================================= # This file configures DynamicSchemaDict required by netbox-branching. -# It imports DATABASE from the NetBox Docker configuration and wraps it. +# It wraps the DATABASE from configuration.py into DATABASES. # Placed in /etc/netbox/config/ # ============================================================================= -import os from netbox_branching.utilities import DynamicSchemaDict -# Build DATABASE dict from environment variables (same as netbox-docker does) -DATABASE = { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': os.environ.get('DB_NAME', 'netbox'), - 'USER': os.environ.get('DB_USER', ''), - 'PASSWORD': os.environ.get('DB_PASSWORD', ''), - 'HOST': os.environ.get('DB_HOST', 'localhost'), - 'PORT': os.environ.get('DB_PORT', ''), - 'CONN_MAX_AGE': int(os.environ.get('DB_CONN_MAX_AGE', 300)), -} +# Import DATABASE from the already-loaded configuration +# At this point, DATABASE is available in the global namespace from configuration.py +# We need to wrap it with DynamicSchemaDict and delete the original DATABASE # Wrap DATABASES with DynamicSchemaDict for dynamic schema support # This is required for netbox-branching plugin to function correctly @@ -26,6 +18,9 @@ DATABASES = DynamicSchemaDict({ 'default': DATABASE, }) +# Delete DATABASE to avoid "DATABASE and DATABASES may not be set together" error +del DATABASE + # Employ the custom database router for branch-aware queries DATABASE_ROUTERS = [ 'netbox_branching.database.BranchAwareRouter',