Skip to content

Commit 77bfc40

Browse files
Closes #17136: Add read-only database support to the upgrade script (#19247)
1 parent e0b6a31 commit 77bfc40

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

docs/installation/3-netbox.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ Once NetBox has been configured, we're ready to proceed with the actual installa
246246

247247
* Create a Python virtual environment
248248
* Installs all required Python packages
249-
* Run database schema migrations
249+
* Run database schema migrations (skip with `--readonly`)
250250
* Builds the documentation locally (for offline use)
251251
* Aggregate static resource files on disk
252252

@@ -266,6 +266,9 @@ sudo PYTHON=/usr/bin/python3.10 /opt/netbox/upgrade.sh
266266
!!! note
267267
Upon completion, the upgrade script may warn that no existing virtual environment was detected. As this is a new installation, this warning can be safely ignored.
268268

269+
!!! note
270+
To run the script on a node connected to a database in read-only mode, include the `--readonly` parameter. This will skip the application of any database migrations.
271+
269272
## Create a Super User
270273

271274
NetBox does not come with any predefined user accounts. You'll need to create a super user (administrative account) to be able to log into NetBox. First, enter the Python virtual environment created by the upgrade script:

docs/installation/upgrading.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ sudo ./upgrade.sh
154154
sudo PYTHON=/usr/bin/python3.10 ./upgrade.sh
155155
```
156156

157+
!!! note
158+
To run the script on a node connected to a database in read-only mode, include the `--readonly` parameter. This will skip the application of any database migrations.
159+
157160
This script performs the following actions:
158161

159162
* Destroys and rebuilds the Python virtual environment

upgrade.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
# variable (if set), or fall back to "python3". Note that NetBox v4.0+ requires
77
# Python 3.10 or later.
88

9+
# Parse arguments
10+
if [[ "$1" == "--readonly" ]]; then
11+
READONLY_MODE=true
12+
else
13+
READONLY_MODE=false
14+
fi
15+
916
cd "$(dirname "$0")"
1017

1118
NETBOX_VERSION="$(grep ^version netbox/release.yaml | cut -d \" -f2)"
@@ -83,9 +90,14 @@ else
8390
fi
8491

8592
# Apply any database migrations
86-
COMMAND="python3 netbox/manage.py migrate"
87-
echo "Applying database migrations ($COMMAND)..."
88-
eval $COMMAND || exit 1
93+
if [ "$READONLY_MODE" = true ]; then
94+
echo "Skipping database migrations (read-only mode)"
95+
exit 0
96+
else
97+
COMMAND="python3 netbox/manage.py migrate"
98+
echo "Applying database migrations ($COMMAND)..."
99+
eval $COMMAND || exit 1
100+
fi
89101

90102
# Trace any missing cable paths (not typically needed)
91103
COMMAND="python3 netbox/manage.py trace_paths --no-input"

0 commit comments

Comments
 (0)