From d1772275192be6f2cfe476a41e408b40b34d60e6 Mon Sep 17 00:00:00 2001 From: Maurice Date: Tue, 17 Nov 2026 13:41:12 +0100 Subject: [PATCH] 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. --- server/.env.example | 1 + server/scripts/generate-pg-migration.ts | 7 +- server/src/app-config/README.md | 1 + server/src/app-config/derive.ts | 5 + server/src/app-config/env.schema.ts | 4 + .../db/engine/postgres/schema-bootstrap.ts | 92 ++++++- server/src/db/engine/sqlite/sqlite-source.ts | 231 ++++++++++++++++++ server/tests/unit/app-config/derive.test.ts | 9 + server/tests/unit/app-config/validate.test.ts | 7 + .../engine/postgres/schema-bootstrap.test.ts | 79 ++++++ 10 files changed, 426 insertions(+), 10 deletions(-) create mode 100644 server/src/db/engine/sqlite/sqlite-source.ts diff --git a/server/.env.example b/server/.env.example index b9549bece..be19be9c2 100644 --- a/server/.env.example +++ b/server/.env.example @@ -57,6 +57,7 @@ DEMO_MODE=false # Demo mode: resets data hourly # TREK_DB_POOL_MAX=10 # Most connections TREK opens to the Postgres database (1 to 100). Unused on SQLite. (default: 10) # TREK_DB_JOURNAL_MODE=WAL # SQLite journal mode (DELETE, TRUNCATE, PERSIST, MEMORY, WAL, OFF). WAL is fastest and the right choice on local disk. Set DELETE if the data directory lives on network storage (Azure App Service, an SMB/NFS volume on a NAS) — WAL coordinates writers through a shared-memory file that those filesystems do not implement reliably. The mode is stored inside the database file, so it survives a restart; changing this applies on the next boot. # TREK_DB_PRE_MIGRATE_SNAPSHOT=true # Copy the database to data/pre-migrate--