From 77bfc4057915677ba031a9bd0b227811ca5eb962 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 22 Apr 2025 10:42:54 -0400 Subject: [PATCH] Closes #17136: Add read-only database support to the upgrade script (#19247) --- docs/installation/3-netbox.md | 5 ++++- docs/installation/upgrading.md | 3 +++ upgrade.sh | 18 +++++++++++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/docs/installation/3-netbox.md b/docs/installation/3-netbox.md index 60d60d4f0..0a5f51702 100644 --- a/docs/installation/3-netbox.md +++ b/docs/installation/3-netbox.md @@ -246,7 +246,7 @@ Once NetBox has been configured, we're ready to proceed with the actual installa * Create a Python virtual environment * Installs all required Python packages -* Run database schema migrations +* Run database schema migrations (skip with `--readonly`) * Builds the documentation locally (for offline use) * Aggregate static resource files on disk @@ -266,6 +266,9 @@ sudo PYTHON=/usr/bin/python3.10 /opt/netbox/upgrade.sh !!! note 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. +!!! note + 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. + ## Create a Super User 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: diff --git a/docs/installation/upgrading.md b/docs/installation/upgrading.md index 102e8de17..42b8c0187 100644 --- a/docs/installation/upgrading.md +++ b/docs/installation/upgrading.md @@ -154,6 +154,9 @@ sudo ./upgrade.sh sudo PYTHON=/usr/bin/python3.10 ./upgrade.sh ``` +!!! note + 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. + This script performs the following actions: * Destroys and rebuilds the Python virtual environment diff --git a/upgrade.sh b/upgrade.sh index a4db87747..75a3ffc7f 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -6,6 +6,13 @@ # variable (if set), or fall back to "python3". Note that NetBox v4.0+ requires # Python 3.10 or later. +# Parse arguments +if [[ "$1" == "--readonly" ]]; then + READONLY_MODE=true +else + READONLY_MODE=false +fi + cd "$(dirname "$0")" NETBOX_VERSION="$(grep ^version netbox/release.yaml | cut -d \" -f2)" @@ -83,9 +90,14 @@ else fi # Apply any database migrations -COMMAND="python3 netbox/manage.py migrate" -echo "Applying database migrations ($COMMAND)..." -eval $COMMAND || exit 1 +if [ "$READONLY_MODE" = true ]; then + echo "Skipping database migrations (read-only mode)" + exit 0 +else + COMMAND="python3 netbox/manage.py migrate" + echo "Applying database migrations ($COMMAND)..." + eval $COMMAND || exit 1 +fi # Trace any missing cable paths (not typically needed) COMMAND="python3 netbox/manage.py trace_paths --no-input"