Skip to content

Commit

Permalink
Replicate dcim_cablepath table for branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Sep 25, 2024
1 parent d45bc99 commit 49267c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 6 additions & 0 deletions netbox_branching/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
# URL query parameter name
QUERY_PARAM = '_branch'

# Tables which must be replicated within a branch even though their
# models don't directly support branching.
REPLICATE_TABLES = (
'dcim_cablepath',
)

# Models for which branching support is explicitly disabled
EXEMPT_MODELS = (
# Exempt applicable core NetBox models
Expand Down
5 changes: 0 additions & 5 deletions netbox_branching/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ def _get_db(self, model, **hints):
warnings.warn(f"Routing database query for {model} before branching support is initialized.")
return

# Bail if the model does not support branching
app_label, model_name = model._meta.label.lower().split('.')
if model_name not in registry['model_features']['branching'].get(app_label, []):
return

# Return the schema for the active branch (if any)
if branch := active_branch.get():
return f'schema_{branch.schema_name}'
Expand Down
5 changes: 3 additions & 2 deletions netbox_branching/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.db.models import ForeignKey, ManyToManyField
from django.urls import reverse

from .constants import REPLICATE_TABLES
from .contextvars import active_branch

__all__ = (
Expand Down Expand Up @@ -81,9 +82,9 @@ def get_branchable_object_types():

def get_tables_to_replicate():
"""
Returned an ordered list of database tables to replicate when provisioning a new schema.
Return an ordered list of database tables to replicate when provisioning a new schema.
"""
tables = set()
tables = set(REPLICATE_TABLES)

branch_aware_models = [
ot.model_class() for ot in get_branchable_object_types()
Expand Down

0 comments on commit 49267c3

Please sign in to comment.