Files
docker-images/images/netbox/local_settings.py
Damien Arnodo 3ff6ace420
All checks were successful
Build and Push Docker Images / build (push) Successful in 6s
fix: build DATABASE from env vars instead of importing
2026-01-07 15:15:53 +00:00

33 lines
1.3 KiB
Python

# =============================================================================
# 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.
# 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)),
}
# Wrap DATABASES with DynamicSchemaDict for dynamic schema support
# This is required for netbox-branching plugin to function correctly
DATABASES = DynamicSchemaDict({
'default': DATABASE,
})
# Employ the custom database router for branch-aware queries
DATABASE_ROUTERS = [
'netbox_branching.database.BranchAwareRouter',
]