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).
This commit is contained in:
Reynir Björnsson 2024-03-25 16:46:52 +01:00
parent 97b8bb1d85
commit cc6b084d7a
3 changed files with 14 additions and 1 deletions

View file

@ -4,7 +4,8 @@ open Caqti_request.Infix
let application_id = 1234839235l 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 let current_version = 18L
type 'a id = 'a Rep.id type 'a id = 'a Rep.id

View file

@ -77,6 +77,8 @@ done
DB="${DATA_DIR}/builder.sqlite3" DB="${DATA_DIR}/builder.sqlite3"
[ ! -e "$DB" ] && die "The database doesn't exist: '$DB'" [ ! -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;")" DB_VERSION="$(sqlite3 "$DB" "PRAGMA user_version;")"
[ -z "$DB_VERSION" ] && die "Couldn't read database version from '$DB'" [ -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'" [ "$DB_VERSION" -lt 16 ] && die "The database version should be >= 16. It is '$DB_VERSION'"

View file

@ -74,6 +74,16 @@ info "processing UUID '${UUID}'"
DB="${DATA_DIR}/builder.sqlite3" 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 () { get_main_binary () {
sqlite3 "${DB}" "SELECT '_artifacts/' || substr(lower(hex(ba.sha256)), 1, 2) || '/' || lower(hex(ba.sha256)) sqlite3 "${DB}" "SELECT '_artifacts/' || substr(lower(hex(ba.sha256)), 1, 2) || '/' || lower(hex(ba.sha256))
FROM build AS b FROM build AS b