feat(db): run TREK on PostgreSQL

TREK runs on PostgreSQL when TREK_DB_URL is set, and on SQLite as before
otherwise: an engine port under src/db/engine, the dialect helpers under
src/db/dialect, a Postgres baseline for the migrations up to the cut,
pg_dump/pg_restore backups, a probe of every repository method against a
real server and a Postgres test lane in CI.
This commit is contained in:
Isaias Tavares
2026-11-05 01:15:21 -03:00
committed by Maurice
parent 17b47b38b9
commit 2e3762afe1
176 changed files with 6728 additions and 777 deletions
+14
View File
@@ -9,6 +9,7 @@
* listed here pass through untouched (Zod strips unknown keys, it does not
* reject them).
*/
import { DB_POOL_MAX_CEILING } from './db-settings';
import {
isP256PrivateKey,
isServiceKeyShape,
@@ -51,6 +52,14 @@ const url = optionalWith((v) => {
return false;
}
}, 'must be a valid URL (with protocol)');
/** A Postgres connection URL: TREK_DB_URL names no other engine. */
const postgresUrl = optionalWith((v) => {
try {
return ['postgres:', 'postgresql:'].includes(new URL(v).protocol);
} catch {
return false;
}
}, 'must be a postgres:// or postgresql:// URL');
const duration = optionalWith((v) => parseDurationMs(v) != null, 'must be a duration like "1h", "7d" or "30d"');
const oneOf = (values: string[]) =>
optionalWith((v) => values.includes(v.toLowerCase()), `must be one of: ${values.join(', ')}`);
@@ -170,6 +179,11 @@ export const envSchema = z.object({
Path: anyString,
// Data / paths
// A Postgres database instead of the SQLite file. Its value is a secret (it
// carries the password), so it is masked in the boot report.
TREK_DB_URL: postgresUrl,
TREK_DB_POOL_MAX: integer(1, DB_POOL_MAX_CEILING),
TREK_DB_PG_BIN_DIR: anyString,
TREK_DB_FILE: anyString,
// The two SQLite pragmas are deliberately unvalidated: a typo here must fall
// back and warn rather than abort boot, because reset-admin.js — the way out