mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 09:22:15 +00:00
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:
@@ -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).
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user