fix(db): refuse a Postgres boot that would leave a SQLite install behind

Setting TREK_DB_URL on an existing SQLite install booted a new, empty
instance beside its data. The Postgres bootstrap now refuses an empty
database, or a migrated one without a single account, while the data
directory's travel.db holds accounts, and names the move command. A file
that cannot be read counts as holding them. TREK_DB_IGNORE_SQLITE_FILE=true
starts anyway, with a warning; the file is opened read-only and only when
the database holds no TREK data.
This commit is contained in:
Maurice
2026-11-17 13:41:12 +01:00
parent a6bc71787e
commit d177227519
10 changed files with 426 additions and 10 deletions
+1
View File
@@ -168,6 +168,7 @@ OIDC_*, SMTP_*, FORCE_HTTPS, COOKIE_SECURE,
ALLOWED_ORIGINS, UNSPLASH_ACCESS_KEY, WEBAUTHN_*, TZ, ADMIN_EMAIL,
TREK_DB_PRE_MIGRATE_SNAPSHOT(_KEEP) (read when a migration run starts; the
legacy-upgrade suites set it per file),
TREK_DB_IGNORE_SQLITE_FILE (read when a Postgres boot finds no TREK data),
ADMIN_PASSWORD, IDEMPOTENCY_TTL_SECONDS, MCP_RATE_LIMIT (request-path check),
LLM_TIMEOUT_MS, LLM_MAX_OUTPUT_TOKENS, NOMINATIM_URL, VAPID_* (resolved per use by the Web Push key
service, which the notification suites build without the container).
+5
View File
@@ -383,6 +383,11 @@ export function deriveDb(raw: RawEnv) {
preMigrateSnapshot: parseBool(raw.TREK_DB_PRE_MIGRATE_SNAPSHOT),
/** How many pre-migration snapshots stay in the data dir, newest first. */
preMigrateSnapshotKeep: Math.min(positiveIntOr(raw.TREK_DB_PRE_MIGRATE_SNAPSHOT_KEEP, 3), 100),
/**
* Start on Postgres although data/travel.db holds a SQLite install with
* accounts. Only an explicit true: anything else keeps the refusal.
*/
ignoreSqliteFile: parseBool(raw.TREK_DB_IGNORE_SQLITE_FILE) === true,
};
}
+4
View File
@@ -197,6 +197,10 @@ export const envSchema = z.object({
// or a misspelt "on" turn it off.
TREK_DB_PRE_MIGRATE_SNAPSHOT: boolStr,
TREK_DB_PRE_MIGRATE_SNAPSHOT_KEEP: integer(1, 100),
// Starts on an empty Postgres database although the data directory holds a
// SQLite install with accounts, which the boot otherwise refuses. Strict like
// the switch above: a misspelt value must not let the refusal through.
TREK_DB_IGNORE_SQLITE_FILE: boolStr,
TREK_WIKI_DIR: anyString,
TREK_PLACE_PHOTO_DIR: anyString,
BACKUP_UPLOAD_LIMIT_MB: positiveNumber,