Skip to content

Commit 006acde

Browse files
Fixes #169: Replicate the global search table for each branch (#236)
* Fixes #169: Replicate the global search table for each branch * Cleanup
1 parent 792db8b commit 006acde

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

netbox_branching/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# must be replicated for each branch to ensure proper functionality
1515
INCLUDE_MODELS = (
1616
'dcim.cablepath',
17+
'extras.cachedvalue',
1718
)
1819

1920
# Models for which branching support is explicitly disabled

netbox_branching/models/branches.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,15 +518,15 @@ def provision(self, user):
518518
cursor.execute(
519519
f"INSERT INTO {schema_table} SELECT * FROM {main_table}"
520520
)
521-
# Get the name of the sequence used for object ID allocations
521+
# Get the name of the sequence used for object ID allocations (if one exists)
522522
cursor.execute(
523523
"SELECT pg_get_serial_sequence(%s, 'id')", [table]
524524
)
525-
sequence_name = cursor.fetchone()[0]
526525
# Set the default value for the ID column to the sequence associated with the source table
527-
cursor.execute(
528-
f"ALTER TABLE {schema_table} ALTER COLUMN id SET DEFAULT nextval(%s)", [sequence_name]
529-
)
526+
if sequence_name := cursor.fetchone()[0]:
527+
cursor.execute(
528+
f"ALTER TABLE {schema_table} ALTER COLUMN id SET DEFAULT nextval(%s)", [sequence_name]
529+
)
530530

531531
# Commit the transaction
532532
cursor.execute("COMMIT")

0 commit comments

Comments
 (0)