From cc6b084d7a4761915534d829355fe010ef62e05e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= Date: Mon, 25 Mar 2024 16:46:52 +0100 Subject: [PATCH] Check version in visualizations.sh If builder-web is upgraded and not restarted the visualizations script will assume the new database schema while the still-running builder-web binary will be using the old schema (until restarted). --- db/builder_db.ml | 3 ++- packaging/batch-viz.sh | 2 ++ packaging/visualizations.sh | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/db/builder_db.ml b/db/builder_db.ml index 63fbeac..f2950b7 100644 --- a/db/builder_db.ml +++ b/db/builder_db.ml @@ -4,7 +4,8 @@ open Caqti_request.Infix let application_id = 1234839235l -(* Please update this when making changes! *) +(* Please update this when making changes! And also update + packaging/batch-viz.sh and packaging/visualizations.sh. *) let current_version = 18L type 'a id = 'a Rep.id diff --git a/packaging/batch-viz.sh b/packaging/batch-viz.sh index 95236c3..bc2ae3b 100755 --- a/packaging/batch-viz.sh +++ b/packaging/batch-viz.sh @@ -77,6 +77,8 @@ done DB="${DATA_DIR}/builder.sqlite3" [ ! -e "$DB" ] && die "The database doesn't exist: '$DB'" +# Let's be somewhat lenient with the database version. +# In visualizations.sh we can be more strict. DB_VERSION="$(sqlite3 "$DB" "PRAGMA user_version;")" [ -z "$DB_VERSION" ] && die "Couldn't read database version from '$DB'" [ "$DB_VERSION" -lt 16 ] && die "The database version should be >= 16. It is '$DB_VERSION'" diff --git a/packaging/visualizations.sh b/packaging/visualizations.sh index 5e575df..50c99d9 100755 --- a/packaging/visualizations.sh +++ b/packaging/visualizations.sh @@ -74,6 +74,16 @@ info "processing UUID '${UUID}'" DB="${DATA_DIR}/builder.sqlite3" +# A new visualizations.sh script may be installed during an upgrade while the +# old builder-web binary is running. In that case things can get out of sync. +DB_VERSION="$(sqlite3 "$DB" "PRAGMA user_version;")" +[ -z "$DB_VERSION" ] && die "Couldn't read database version from '$DB'" +[ "$DB_VERSION" -ne 18 ] && die "The database version should be 18. It is '$DB_VERSION'" + +APP_ID="$(sqlite3 "$DB" "PRAGMA application_id;")" +[ -z "$APP_ID" ] && die "Couldn't read application-id from '$DB'" +[ "$APP_ID" -ne 1234839235 ] && die "The application-id should be 1234839235. It is '$APP_ID'" + get_main_binary () { sqlite3 "${DB}" "SELECT '_artifacts/' || substr(lower(hex(ba.sha256)), 1, 2) || '/' || lower(hex(ba.sha256)) FROM build AS b