Skip to content

Fixes #98: Cable changes in branch should not impact main schema #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this isn't needed anymore, won't affect plugins and such? Didn't know how to test that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct; this was originally addressed under #59 but isn't technically needed.

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