Skip to content

Commit 47891cc

Browse files
249 Update documentation for NetBox v4.3 DATABASES config change (#266)
* #249 update documentation for NetBox v4.3 DATABASES config change * #249 update documentation for NetBox v4.3 DATABASES config change * #249 update documentation for NetBox v4.3 DATABASES config change * #249 update documentation for NetBox v4.3 DATABASES config change * #249 update documentation for NetBox v4.3 DATABASES config change * #249 update documentation for NetBox v4.3 DATABASES config change * Simplify quick start instructions * Restructure installation documentation --------- Co-authored-by: Jeremy Stretch <[email protected]>
1 parent de954b7 commit 47891cc

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This [NetBox](http://netboxlabs.com/oss/netbox/) plugin introduces branching fun
44

55
## Requirements
66

7-
* NetBox v4.1 or later
7+
* NetBox v4.3 or later
88
* PostgreSQL 12 or later
99

1010
## Installation
@@ -38,18 +38,23 @@ PLUGINS = [
3838
]
3939
```
4040

41-
5. Create `local_settings.py` (in the same directory as `settings.py`) to override the `DATABASES` & `DATABASE_ROUTERS` settings. This enables dynamic schema support.
41+
5. Configure the database and router in `configuration.py`:
4242

4343
```python
4444
from netbox_branching.utilities import DynamicSchemaDict
45-
from .configuration import DATABASE
4645

47-
# Wrap DATABASES with DynamicSchemaDict for dynamic schema support
4846
DATABASES = DynamicSchemaDict({
49-
'default': DATABASE,
47+
'default': {
48+
'ENGINE': 'django.db.backends.postgresql',
49+
'NAME': 'netbox', # Database name
50+
'USER': 'netbox', # PostgreSQL username
51+
'PASSWORD': 'password', # PostgreSQL password
52+
'HOST': 'localhost', # Database server
53+
'PORT': '', # Database port (leave blank for default)
54+
'CONN_MAX_AGE': 300, # Max database connection age
55+
}
5056
})
5157

52-
# Employ our custom database router
5358
DATABASE_ROUTERS = [
5459
'netbox_branching.database.BranchAwareRouter',
5560
]

docs/index.md

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,17 @@ sequenceDiagram
7272
Branch->>Main: Merge branch
7373
```
7474

75-
## Getting Started
75+
## Plugin Installation
7676

77-
### Database Preparation
77+
### 1. Database Preparation
7878

7979
Before installing this plugin, ensure that the PostgreSQL user as which NetBox authenticates has permission to create new schemas in the database. This can be achieved by issuing the following command in the PostgreSQL shell (substituting `$database` and `$user` with their respective values):
8080

8181
```postgresql
8282
GRANT CREATE ON DATABASE $database TO $user;
8383
```
8484

85-
### Plugin Installation
86-
87-
#### 1. Virtual Environment
85+
### 2. Virtual Environment
8886

8987
The plugin can be installed from [PyPI](https://pypi.org/project/netboxlabs-netbox-branching/). First, activate the Python virtual environment used by NetBox (which is typically located at `/opt/netbox/venv/`):
9088

@@ -95,15 +93,15 @@ source /opt/netbox/venv/bin/activate
9593
!!! note
9694
You may need to modify the `source` command above if your virtual environment has been installed in a different location.
9795

98-
#### 2. Python Package
96+
### 3. Python Package
9997

10098
Use `pip` to install the Python package:
10199

102100
```
103101
pip install netboxlabs-netbox-branching
104102
```
105103

106-
#### 3. Enable Plugin
104+
### 4. Enable Plugin
107105

108106
Add `netbox_branching` to **the end** of the `PLUGINS` list in `configuration.py`.
109107

@@ -120,12 +118,42 @@ PLUGINS = [
120118
!!! note
121119
If there are no plugins already installed, you might need to create this parameter. If so, be sure to define `PLUGINS` as a list _containing_ the plugin name as above, rather than just the name.
122120

123-
#### 4. Configuration
121+
### 5. Configuration
122+
123+
#### NetBox v4.3 and Later
124+
125+
Wrap your `DATABASES` configuration parameter with `DynamicSchemaDict` in `configuration.py`, as shown below.
126+
127+
!!! note
128+
If upgrading from an earlier version of NetBox, you may need to replace the legacy `DATABASE` (singular) parameter with `DATABASES` (plural).
129+
130+
```python
131+
from netbox_branching.utilities import DynamicSchemaDict
132+
133+
DATABASES = DynamicSchemaDict({
134+
'default': {
135+
'ENGINE': 'django.db.backends.postgresql',
136+
'NAME': 'netbox',
137+
'USER': 'netbox',
138+
...
139+
}
140+
})
141+
```
142+
143+
Additionally, declare `DATABASE_ROUTERS` to employ the plugin's custom database router to support branching.
144+
145+
```python
146+
DATABASE_ROUTERS = [
147+
'netbox_branching.database.BranchAwareRouter',
148+
]
149+
```
124150

125-
This plugin employs dynamic schema resolution, which requires that we override two low-level Django settings. First, we'll wrap NetBox's configured `DATABASE` parameter with `DynamicSchemaDict` to support dynamic schemas. Second, we'll employ the plugin's custom database router.
151+
#### NetBox v4.2 and Earlier
126152

127-
Create a new file named `local_settings.py` in the same directory as `settings.py`, and add the content below.
153+
If using NetBox v4.2 or earlier, these changes must be made in `local_settings.py`, as the `DATABASES` and `DATABASE_ROUTERS` configuration parameters were not introduced until NetBox v4.3.
128154

155+
Create a file named `local_settings.py` in the same directory as `configuration.py`, and add the following content.
156+
129157
```python
130158
from netbox_branching.utilities import DynamicSchemaDict
131159
from .configuration import DATABASE
@@ -141,7 +169,7 @@ DATABASE_ROUTERS = [
141169
]
142170
```
143171

144-
#### 5. Database Migrations
172+
### 6. Database Migrations
145173

146174
Run the included database migrations:
147175

0 commit comments

Comments
 (0)