From 4f1908fc6b817a9b19f84f08d517e6e3aa9d3008 Mon Sep 17 00:00:00 2001 From: repo-worker-code Date: Sun, 8 Nov 2026 00:44:54 -0600 Subject: [PATCH 1/2] fix(pm-stack backup): resolve pmp_links source DB correctly and assert both offsite legs The pmp_links export added by #5315 still had unresolved review gaps (code#7096): - DATABASE_URL is read from the LAST matching env-file assignment (a later line is what the service loads), with CR, edge whitespace and one matching quote pair trimmed. The old tr deleted every quote/space in the value, mangling paths with spaces. - file: URL paths are percent-decoded and file:/// and file://localhost/ authorities stripped before the existence check. - An unsupported non-file DATABASE_URL (postgres://, libsql://, ...) now fails the run instead of silently archiving a stale local DB; the failure names only the scheme, never the DSN (it may embed credentials). - With no configured source, /projector.db is used before the ~/.local/state/pm-projector fallback; a relative value resolves under PM_PROJECTOR_DIR. - The with-db scenario now passes only when the stub log records copyto to BOTH R2 and Drive for the same archive, plus new scenarios for last-assignment, quoted/CR/percent-encoded values, remote-DSN rejection, and relative/PM_PROJECTOR_DIR resolution. Refs #7096, #1744 --- .../pm-dashboard-backup-pmp-links.test.sh | 129 +++++++++++++++++- nixos/home/pm-dashboard-backup.sh | 98 +++++++++++-- 2 files changed, 210 insertions(+), 17 deletions(-) diff --git a/nixos/home/pm-dashboard-backup-pmp-links.test.sh b/nixos/home/pm-dashboard-backup-pmp-links.test.sh index 00c195510b..6804254d87 100755 --- a/nixos/home/pm-dashboard-backup-pmp-links.test.sh +++ b/nixos/home/pm-dashboard-backup-pmp-links.test.sh @@ -21,9 +21,25 @@ # at the default state path: run completes and uploads; the # archive's projector/pmp_links.sql restores into a scratch DB # with content identical to the source, contains NO pmp_items -# data, and the manifest records the member required + present. +# data, and the manifest records the member required + present; +# the stub log shows copyto calls to BOTH offsite legs (R2 and +# Drive) for the same archive. # * env-url — the env file's database URL points at a fixture DB # elsewhere: the export comes from THAT database. +# * env-last — two DATABASE_URL assignments in the env file: the +# LAST one selects the source (the stale first one must not). +# * env-quoted — the last assignment is quoted, CR-terminated and +# percent-encoded, and its path contains a space: the quote pair, +# CR and edge whitespace are trimmed, the %XX escapes decoded, and +# interior spaces preserved. +# * env-remote — DATABASE_URL names a non-file DSN: the run fails +# explicitly (nothing is uploaded, the cursor is unchanged, the +# failure names pmp_links and does not leak the DSN). +# * env-relative — DATABASE_URL names a relative path and +# PM_PROJECTOR_DIR is set: the DB resolves under that directory. +# * projector-dir — no DATABASE_URL, PM_PROJECTOR_DIR names a dir +# holding projector.db while the state-dir default also exists: +# the PM_PROJECTOR_DIR DB wins. # * no-db — no projector DB anywhere: run completes, manifest # records the member optional + missing. # * corrupt-db — the configured DB file is garbage: run fails, @@ -139,10 +155,15 @@ SQL run_backup() { local name="$1" - HOME="$RUN_HOME" PATH="$BIN:$PATH" BWS_ACCESS_TOKEN="test-token" \ + shift + # PM_PROJECTOR_* are cleared so an ambient value can never pick the + # source for a scenario; scenarios pass their own as env(1) arguments. + env -u PM_PROJECTOR_DIR -u PM_PROJECTOR_DB -u PM_PROJECTOR_ENV \ + HOME="$RUN_HOME" PATH="$BIN:$PATH" BWS_ACCESS_TOKEN="test-token" \ RCLONE_STUB_DIR="$TMP_ROOT/$name/rclone-store" \ RCLONE_CALLS_LOG="$TMP_ROOT/$name/rclone-calls.log" \ PM_DB_DUMP_SCRIPT="$RUN_HOME/no-such-dump-script.sh" \ + "$@" \ bash "$SCRIPT" 2026-10-28 >"$TMP_ROOT/$name.log" 2>&1 RC=$? MARKER_AFTER="$(cat "$RUN_HOME/backups/dashboard/.last-run-epoch" 2>/dev/null || echo missing)" @@ -178,6 +199,13 @@ no_upload() { # $1 scenario name || ! grep -q '^copyto' "$TMP_ROOT/$1/rclone-calls.log" } +copied_both() { # $1 scenario name — copyto recorded for BOTH offsite legs + local log="$TMP_ROOT/$1/rclone-calls.log" + [[ -f "$log" ]] || return 1 + grep -qE '^copyto .*/dashboard-2026-10-28\.tar\.zst r2bak:.*/dashboard-2026-10-28\.tar\.zst$' "$log" && + grep -qE '^copyto .*/dashboard-2026-10-28\.tar\.zst drive:.*/dashboard-2026-10-28\.tar\.zst$' "$log" +} + canonical_links() { # $1 = sqlite db path; canonical pmp_links content sqlite3 "file:$1?mode=ro" '.dump pmp_links' } @@ -218,10 +246,10 @@ else fail "with-db: restored pmp_links content differs from source" fi assert_member with-db required present -if ! no_upload with-db; then - ok "with-db: archive uploaded to the offsite legs (stub rclone copyto recorded)" +if copied_both with-db; then + ok "with-db: stub log records copyto to both R2 and Drive" else - fail "with-db: expected uploads to the offsite legs" + fail "with-db: expected copyto to BOTH R2 and Drive; calls: $(cat "$TMP_ROOT/with-db/rclone-calls.log" 2>/dev/null || echo none)" fi # --- env-url: the env file's database URL selects the source DB ---------------- @@ -239,6 +267,97 @@ else fi assert_member env-url required present +# --- env-last: the LAST DATABASE_URL assignment selects the source ------------- +setup_home env-last +mkdir -p "$RUN_HOME/elsewhere" "$RUN_HOME/.local/state/pm-projector" +make_fixture_db "$RUN_HOME/elsewhere/stale.db" 'stale-first-link-note' +make_fixture_db "$RUN_HOME/elsewhere/live.db" 'last-assignment-link-note' +{ + printf '%s=file:%s\n' 'DATABASE_URL' "$RUN_HOME/elsewhere/stale.db" + printf '%s=file:%s\n' 'DATABASE_URL' "$RUN_HOME/elsewhere/live.db" +} >"$RUN_HOME/.local/state/pm-projector/.env" +run_backup env-last +D="$(archive_dir env-last)" +if [[ "$RC" -eq 0 ]] \ + && grep -q 'last-assignment-link-note' "$D/projector/pmp_links.sql" 2>/dev/null \ + && ! grep -q 'stale-first-link-note' "$D/projector/pmp_links.sql" 2>/dev/null; then + ok "env-last: export sourced from the last DATABASE_URL assignment" +else + fail "env-last: export did not come from the last assignment (rc=$RC); log: $(cat "$TMP_ROOT/env-last.log")" +fi + +# --- env-quoted: quotes, CR, edge space trimmed; %XX decoded ------------------- +setup_home env-quoted +mkdir -p "$RUN_HOME/with space" "$RUN_HOME/.local/state/pm-projector" +make_fixture_db "$RUN_HOME/with space/quoted db.db" 'quoted-encoded-link-note' +printf 'DATABASE_URL = "file:%s/with%%20space/quoted%%20db.db" \r\n' "$RUN_HOME" \ + >"$RUN_HOME/.local/state/pm-projector/.env" +run_backup env-quoted +D="$(archive_dir env-quoted)" +if [[ "$RC" -eq 0 ]] && grep -q 'quoted-encoded-link-note' "$D/projector/pmp_links.sql" 2>/dev/null; then + ok "env-quoted: quoted, CR-terminated, percent-encoded URL resolved to the real DB" +else + fail "env-quoted: quoted/encoded URL was not resolved (rc=$RC); log: $(cat "$TMP_ROOT/env-quoted.log")" +fi + +# --- env-remote: a non-file DSN fails explicitly, no local fallback ----------- +setup_home env-remote +mkdir -p "$RUN_HOME/.local/state/pm-projector" +# A local DB exists at the fallback path: it must NOT be silently archived. +make_fixture_db "$RUN_HOME/.local/state/pm-projector/projector.db" 'fallback-must-not-be-used' +printf '%s=postgres://user:sup3rsecret@db.example.invalid/app\n' 'DATABASE_URL' \ + >"$RUN_HOME/.local/state/pm-projector/.env" +run_backup env-remote +if [[ "$RC" -ne 0 ]]; then + ok "env-remote: remote DATABASE_URL fails the run ($RC)" +else + fail "env-remote: remote DATABASE_URL silently accepted (exit 0)" +fi +if grep -q 'pmp_links' "$TMP_ROOT/env-remote.log" \ + && ! grep -q 'sup3rsecret' "$TMP_ROOT/env-remote.log"; then + ok "env-remote: failure names pmp_links and does not leak the DSN" +else + fail "env-remote: failure output missing pmp_links or leaked the DSN: $(cat "$TMP_ROOT/env-remote.log")" +fi +if no_upload env-remote; then + ok "env-remote: nothing uploaded" +else + fail "env-remote: an upload was attempted" +fi +if [[ "$MARKER_AFTER" == "$PRESET" ]]; then + ok "env-remote: journal marker unchanged" +else + fail "env-remote: marker advanced — was $PRESET, now $MARKER_AFTER" +fi + +# --- env-relative: relative DB resolves under PM_PROJECTOR_DIR ----------------- +setup_home env-relative +mkdir -p "$RUN_HOME/projector" "$RUN_HOME/.local/state/pm-projector" +make_fixture_db "$RUN_HOME/projector/rel.db" 'relative-dir-link-note' +printf '%s=file:rel.db\n' 'DATABASE_URL' >"$RUN_HOME/.local/state/pm-projector/.env" +run_backup env-relative PM_PROJECTOR_DIR="$RUN_HOME/projector" +D="$(archive_dir env-relative)" +if [[ "$RC" -eq 0 ]] && grep -q 'relative-dir-link-note' "$D/projector/pmp_links.sql" 2>/dev/null; then + ok "env-relative: relative DB resolved under PM_PROJECTOR_DIR" +else + fail "env-relative: relative DB not resolved under PM_PROJECTOR_DIR (rc=$RC); log: $(cat "$TMP_ROOT/env-relative.log")" +fi + +# --- projector-dir: PM_PROJECTOR_DIR default wins over the state-dir fallback -- +setup_home projector-dir +mkdir -p "$RUN_HOME/projector" "$RUN_HOME/.local/state/pm-projector" +make_fixture_db "$RUN_HOME/projector/projector.db" 'projector-dir-link-note' +make_fixture_db "$RUN_HOME/.local/state/pm-projector/projector.db" 'state-dir-fallback-link-note' +run_backup projector-dir PM_PROJECTOR_DIR="$RUN_HOME/projector" +D="$(archive_dir projector-dir)" +if [[ "$RC" -eq 0 ]] \ + && grep -q 'projector-dir-link-note' "$D/projector/pmp_links.sql" 2>/dev/null \ + && ! grep -q 'state-dir-fallback-link-note' "$D/projector/pmp_links.sql" 2>/dev/null; then + ok "projector-dir: PM_PROJECTOR_DIR DB chosen before the state-dir fallback" +else + fail "projector-dir: PM_PROJECTOR_DIR DB not chosen (rc=$RC); log: $(cat "$TMP_ROOT/projector-dir.log")" +fi + # --- no-db: not applicable, recorded optional + missing ------------------------ setup_home no-db run_backup no-db diff --git a/nixos/home/pm-dashboard-backup.sh b/nixos/home/pm-dashboard-backup.sh index 72de21e294..9319e950c8 100755 --- a/nixos/home/pm-dashboard-backup.sh +++ b/nixos/home/pm-dashboard-backup.sh @@ -379,29 +379,103 @@ if [ -d "$DUMP_DIR" ]; then cp -a "$DUMP_DIR" "$STAGE/db-dumps" || fail "dataset copy failed: $DUMP_DIR"; fi # --- pmp_links export (code#1744 P0) ---------------------------------- -# Source: the ACTUAL configured projector database — DATABASE_URL in the -# pm-projector env file when it names a file: URL, else the deployed -# default ~/.local/state/pm-projector/projector.db (a relative file: -# value resolves against the projector unit's working directory). +# Source: the ACTUAL configured projector database — the LAST DATABASE_URL +# assignment in the pm-projector env file when it names a file: URL +# (percent-decoded) or a local path, else /projector.db +# when that directory is named, else the deployed default +# ~/.local/state/pm-projector/projector.db (a relative value resolves +# against PM_PROJECTOR_DIR). A remote (non-file) DATABASE_URL fails the +# run: exporting a stale local DB instead would make the archive evidence +# claim a source it never read. # PM_PROJECTOR_DB / PM_PROJECTOR_ENV override both (tests, relocation). # Only the pmp_links table is exported (schema + rows as SQL): the rest # of projector.db is a rebuildable projection and credentials never # enter the archive — the .env file itself is NOT read beyond the # DATABASE_URL line and is never staged. +# Env-file value -> path/URL: strip one trailing CR, edge whitespace and a +# single matching quote pair, leaving interior characters (spaces, quotes) +# untouched — only the value's edges are syntax, the path itself is data. +pmp_trim_value() { + local v="$1" + v="${v%$'\r'}" + v="${v#"${v%%[![:space:]]*}"}" + v="${v%"${v##*[![:space:]]}"}" + if ((${#v} >= 2)); then + case "$v" in + \"*\") v="${v:1:${#v}-2}" ;; + \'*\') v="${v:1:${#v}-2}" ;; + esac + fi + printf '%s' "$v" +} +# Percent-decode a file: URL path (%20 -> space, %2F -> /, ...). Malformed +# escapes are kept literally rather than dropped. +pmp_url_decode() { + local in="$1" out="" byte + while [[ "$in" == *%* ]]; do + out+="${in%%\%*}" + in="${in#*\%}" + if [[ "${in:0:2}" =~ ^[0-9A-Fa-f]{2}$ ]]; then + printf -v byte "\\x${in:0:2}" + out+="$byte" + in="${in:2}" + else + out+="%" + fi + done + printf '%s' "$out$in" +} PMP_DB="${PM_PROJECTOR_DB:-}" if [ -z "$PMP_DB" ]; then PMP_ENV="${PM_PROJECTOR_ENV:-$HOME/.local/state/pm-projector/.env}" + PMP_URL="" if [ -f "$PMP_ENV" ]; then - _url="$(grep -m1 '^DATABASE_URL=' "$PMP_ENV" 2>/dev/null | cut -d= -f2- | tr -d '"'"'"' \r')" - case "$_url" in - file:*) PMP_DB="${_url#file:}"; PMP_DB="${PMP_DB%%\?*}" ;; + # The LAST assignment wins: a later line is what the service loads. + PMP_URL="$(grep -E '^[[:space:]]*(export[[:space:]]+)?DATABASE_URL[[:space:]]*=' "$PMP_ENV" 2>/dev/null | + tail -n 1 | sed -E 's/^[[:space:]]*(export[[:space:]]+)?DATABASE_URL[[:space:]]*=//')" + fi + PMP_URL="$(pmp_trim_value "$PMP_URL")" + PMP_DIR="${PM_PROJECTOR_DIR:-}" + if [ -n "$PMP_URL" ]; then + case "$PMP_URL" in + file:*) + PMP_DB="${PMP_URL#file:}" + PMP_DB="${PMP_DB%%\?*}" + PMP_DB="${PMP_DB%%#*}" + # file://host/path -> /path: drop an empty or localhost + # authority, then decode the path before any existence check. + case "$PMP_DB" in + //localhost/*) PMP_DB="/${PMP_DB#//localhost/}" ;; + ///*) PMP_DB="/${PMP_DB#///}" ;; + esac + PMP_DB="$(pmp_url_decode "$PMP_DB")" + ;; + *://*) + # Remote DSN (postgres://, libsql://, ...): this export cannot + # read it, and silently archiving a local file instead would make + # the archive claim a source it never read. Name the scheme only + # — a DSN may embed credentials. + fail "pmp_links export failed: DATABASE_URL in $PMP_ENV uses '${PMP_URL%%://*}://', which is not supported (only file: URLs or local paths); remote export is not implemented" + ;; + *) + PMP_DB="$PMP_URL" # local path, absolute or relative + ;; + esac + fi + if [ -z "$PMP_DB" ]; then + # Nothing configured: the active DB is /projector.db + # when that dir is named, else the deployed state-directory default. + if [ -n "$PMP_DIR" ] && [ -f "$PMP_DIR/projector.db" ]; then + PMP_DB="$PMP_DIR/projector.db" + else + PMP_DB="$HOME/.local/state/pm-projector/projector.db" + fi + else + case "$PMP_DB" in + /*) ;; + *) PMP_DB="${PMP_DIR:-$HOME/git/code/pm-stack/projector}/$PMP_DB" ;; esac fi - [ -n "$PMP_DB" ] || PMP_DB="$HOME/.local/state/pm-projector/projector.db" - case "$PMP_DB" in - /*) ;; - *) PMP_DB="${PM_PROJECTOR_DIR:-$HOME/git/code/pm-stack/projector}/$PMP_DB" ;; - esac fi if [ -f "$PMP_DB" ]; then command -v sqlite3 >/dev/null 2>&1 || From afda12dd07e71dd8856a9de925a93daf8790635e Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Sun, 8 Nov 2026 02:49:30 -0600 Subject: [PATCH 2/2] fix(pm-stack backup): resolve projector default under data/ and open DB read-only by path Codex review on PR #7363, two P2 findings: (1) the projector default is file:data/projector.db relative to its working directory (pm-stack/projector/src/store.ts), so the PM_PROJECTOR_DIR fallback now resolves data/projector.db and never a stale root projector.db; the projector-dir fixture now covers the stale-root case. (2) A percent-decoded path containing ? or # broke when re-interpolated into a file:...?mode=ro SQLite URI; the export now opens the decoded path with sqlite3 -readonly instead. New env-encoded-q case covers a literal ? filename. Targeted suites pass: pm-dashboard-backup-pmp-links.test.sh, pm-dashboard-backup-manifest.test.sh. --- .../pm-dashboard-backup-pmp-links.test.sh | 36 ++++++++++++++----- nixos/home/pm-dashboard-backup.sh | 20 ++++++----- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/nixos/home/pm-dashboard-backup-pmp-links.test.sh b/nixos/home/pm-dashboard-backup-pmp-links.test.sh index 6804254d87..2510e602b7 100755 --- a/nixos/home/pm-dashboard-backup-pmp-links.test.sh +++ b/nixos/home/pm-dashboard-backup-pmp-links.test.sh @@ -37,9 +37,14 @@ # failure names pmp_links and does not leak the DSN). # * env-relative — DATABASE_URL names a relative path and # PM_PROJECTOR_DIR is set: the DB resolves under that directory. -# * projector-dir — no DATABASE_URL, PM_PROJECTOR_DIR names a dir -# holding projector.db while the state-dir default also exists: -# the PM_PROJECTOR_DIR DB wins. +# * projector-dir — no DATABASE_URL, PM_PROJECTOR_DIR names the +# projector working dir: the active DB is data/projector.db under +# it (the projector own default), and it wins over a stale +# projector.db at the dir root and over the state-dir default. +# * env-encoded-q — DATABASE_URL is file:...projector%3Fprod.db: +# the decoded path names a real file with a literal ? in its name, +# and that exact file is exported (the decoded ? must not turn +# into SQLite URI query syntax). # * no-db — no projector DB anywhere: run completes, manifest # records the member optional + missing. # * corrupt-db — the configured DB file is garbage: run fails, @@ -345,17 +350,32 @@ fi # --- projector-dir: PM_PROJECTOR_DIR default wins over the state-dir fallback -- setup_home projector-dir -mkdir -p "$RUN_HOME/projector" "$RUN_HOME/.local/state/pm-projector" -make_fixture_db "$RUN_HOME/projector/projector.db" 'projector-dir-link-note' +mkdir -p "$RUN_HOME/projector/data" "$RUN_HOME/.local/state/pm-projector" +make_fixture_db "$RUN_HOME/projector/data/projector.db" 'projector-dir-link-note' +make_fixture_db "$RUN_HOME/projector/projector.db" 'stale-root-link-note' make_fixture_db "$RUN_HOME/.local/state/pm-projector/projector.db" 'state-dir-fallback-link-note' run_backup projector-dir PM_PROJECTOR_DIR="$RUN_HOME/projector" D="$(archive_dir projector-dir)" if [[ "$RC" -eq 0 ]] \ && grep -q 'projector-dir-link-note' "$D/projector/pmp_links.sql" 2>/dev/null \ - && ! grep -q 'state-dir-fallback-link-note' "$D/projector/pmp_links.sql" 2>/dev/null; then - ok "projector-dir: PM_PROJECTOR_DIR DB chosen before the state-dir fallback" + && ! grep -q 'stale-root-link-note' "$D/projector/pmp_links.sql" 2>/dev/null && ! grep -q 'state-dir-fallback-link-note' "$D/projector/pmp_links.sql" 2>/dev/null; then + ok "projector-dir: PM_PROJECTOR_DIR/data DB chosen before stale-root and state-dir DBs" +else + fail "projector-dir: PM_PROJECTOR_DIR/data DB not chosen (rc=$RC); log: $(cat "$TMP_ROOT/projector-dir.log")" +fi + +# --- env-encoded-q: decoded ? in the filename stays a filename character ----- +setup_home env-encoded-q +mkdir -p "$RUN_HOME/elsewhere" "$RUN_HOME/.local/state/pm-projector" +make_fixture_db "$RUN_HOME/elsewhere/projector?prod.db" 'encoded-q-link-note' +printf '%s=file:%s +' 'DATABASE_URL' "$RUN_HOME/elsewhere/projector%3Fprod.db" >"$RUN_HOME/.local/state/pm-projector/.env" +run_backup env-encoded-q +D="$(archive_dir env-encoded-q)" +if [[ "$RC" -eq 0 ]] && grep -q 'encoded-q-link-note' "$D/projector/pmp_links.sql" 2>/dev/null; then + ok "env-encoded-q: percent-decoded ? filename exported as-is" else - fail "projector-dir: PM_PROJECTOR_DIR DB not chosen (rc=$RC); log: $(cat "$TMP_ROOT/projector-dir.log")" + fail "env-encoded-q: decoded ? filename not exported (rc=$RC); log: $(cat "$TMP_ROOT/env-encoded-q.log")" fi # --- no-db: not applicable, recorded optional + missing ------------------------ diff --git a/nixos/home/pm-dashboard-backup.sh b/nixos/home/pm-dashboard-backup.sh index 9319e950c8..99bfaf6d5b 100755 --- a/nixos/home/pm-dashboard-backup.sh +++ b/nixos/home/pm-dashboard-backup.sh @@ -381,7 +381,7 @@ if [ -d "$DUMP_DIR" ]; then cp -a "$DUMP_DIR" "$STAGE/db-dumps" || # --- pmp_links export (code#1744 P0) ---------------------------------- # Source: the ACTUAL configured projector database — the LAST DATABASE_URL # assignment in the pm-projector env file when it names a file: URL -# (percent-decoded) or a local path, else /projector.db +# (percent-decoded) or a local path, else /data/projector.db # when that directory is named, else the deployed default # ~/.local/state/pm-projector/projector.db (a relative value resolves # against PM_PROJECTOR_DIR). A remote (non-file) DATABASE_URL fails the @@ -463,10 +463,14 @@ if [ -z "$PMP_DB" ]; then esac fi if [ -z "$PMP_DB" ]; then - # Nothing configured: the active DB is /projector.db - # when that dir is named, else the deployed state-directory default. - if [ -n "$PMP_DIR" ] && [ -f "$PMP_DIR/projector.db" ]; then - PMP_DB="$PMP_DIR/projector.db" + # Nothing configured: the projector's own default is + # file:data/projector.db relative to its working directory + # (pm-stack/projector/src/store.ts), so the active DB is + # /data/projector.db when that dir is named, + # else the deployed state-directory default. A projector.db at + # the directory root is NOT the active DB and is never picked. + if [ -n "$PMP_DIR" ] && [ -f "$PMP_DIR/data/projector.db" ]; then + PMP_DB="$PMP_DIR/data/projector.db" else PMP_DB="$HOME/.local/state/pm-projector/projector.db" fi @@ -480,14 +484,14 @@ fi if [ -f "$PMP_DB" ]; then command -v sqlite3 >/dev/null 2>&1 || fail "sqlite3 not found — cannot export pmp_links from $PMP_DB" - PMP_ROWS="$(sqlite3 "file:$PMP_DB?mode=ro" 'SELECT COUNT(*) FROM pmp_links;' 2>/dev/null)" || + PMP_ROWS="$(sqlite3 -readonly "$PMP_DB" 'SELECT COUNT(*) FROM pmp_links;' 2>/dev/null)" || fail "pmp_links export failed: cannot read pmp_links in $PMP_DB" mkdir -p "$STAGE/projector" - sqlite3 "file:$PMP_DB?mode=ro" '.dump pmp_links' >"$STAGE/projector/pmp_links.sql" || + sqlite3 -readonly "$PMP_DB" '.dump pmp_links' >"$STAGE/projector/pmp_links.sql" || fail "pmp_links export failed: .dump of $PMP_DB" # .dump omits the table's indexes on this sqlite build — append them # from sqlite_master so a restore reproduces the full table shape. - sqlite3 "file:$PMP_DB?mode=ro" \ + sqlite3 -readonly "$PMP_DB" \ "SELECT sql || ';' FROM sqlite_master WHERE type = 'index' AND tbl_name = 'pmp_links' AND sql IS NOT NULL;" \ >>"$STAGE/projector/pmp_links.sql" || fail "pmp_links export failed: index definitions of $PMP_DB"