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
+21 -1
View File
@@ -33,6 +33,7 @@ export const SECRET_ENV_KEYS: ReadonlySet<string> = new Set([
'MAPBOX_ACCESS_TOKEN',
'CARTO_API_KEY',
'DEMO_ADMIN_PASS',
'TREK_DB_URL',
'MAIL_INGEST_IMAP_PASS',
'MAIL_INGEST_WEBHOOK_SECRET',
]);
@@ -97,7 +98,7 @@ export function validateEnvAtBoot(raw: RawEnv = process.env as RawEnv): void {
const key = String(issue.path[0]);
return ` - ${key}=${reportedValue(key, raw[key])}: ${issue.message}`;
});
lines.push(...managedPreconditions(raw));
lines.push(...databasePreconditions(raw), ...managedPreconditions(raw));
if (lines.length === 0) return;
console.error(`Invalid environment configuration:\n${lines.join('\n')}`);
throw new Error(
@@ -106,6 +107,25 @@ export function validateEnvAtBoot(raw: RawEnv = process.env as RawEnv): void {
);
}
/** The SQLite settings that mean nothing next to TREK_DB_URL. */
const SQLITE_ONLY_DB_KEYS = ['TREK_DB_FILE', 'TREK_DB_JOURNAL_MODE', 'TREK_DB_SYNCHRONOUS'] as const;
/**
* Cross-field rules for the database engine. TREK_DB_URL beside a SQLite
* setting names two databases, and either guess would leave the operator on
* the one they did not mean: it refuses instead (fail closed, see
* server/CLAUDE.md). The URL itself never reaches the report.
*/
function databasePreconditions(raw: RawEnv): string[] {
if (!raw.TREK_DB_URL?.trim()) return [];
const sqliteKeys = SQLITE_ONLY_DB_KEYS.filter((key) => raw[key]?.trim());
if (sqliteKeys.length === 0) return [];
return [
` - ambiguous database configuration: TREK_DB_URL is set together with ${sqliteKeys.join(', ')}, ` +
'which only apply to the SQLite file. Unset one side.',
];
}
/**
* Cross-field rules that only apply to a centrally administered install.
*