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
@@ -341,3 +341,40 @@ describe('validateEnvAtBoot: the pre-migration snapshot switches', () => {
);
});
});
describe('validateEnvAtBoot: the database engine', () => {
afterEach(() => {
vi.restoreAllMocks();
});
it('DB-BOOT-001: refuses a TREK_DB_URL that is not a postgres:// or postgresql:// URL, without printing it', () => {
for (const value of ['mysql://u:secret@db/trek', 'not a url', 'sqlite:///data/travel.db']) {
const { printed, thrown } = bootReport({ TREK_DB_URL: value });
expect(thrown, value).toMatch(/Invalid environment configuration/);
expect(printed, value).toContain('TREK_DB_URL=***');
expect(printed, value).not.toContain('secret');
}
});
it('DB-BOOT-002: masks TREK_DB_URL like every other secret', () => {
expect(SECRET_ENV_KEYS.has('TREK_DB_URL')).toBe(true);
});
it('DB-BOOT-003: refuses TREK_DB_URL together with a SQLite setting, naming both', () => {
for (const key of ['TREK_DB_FILE', 'TREK_DB_JOURNAL_MODE', 'TREK_DB_SYNCHRONOUS']) {
const { thrown, printed } = bootReport({ TREK_DB_URL: 'postgres://u:p@db/trek', [key]: 'x' });
expect(thrown, key).toMatch(/Invalid environment configuration/);
expect(printed, key).toContain('ambiguous database configuration');
expect(printed, key).toContain(key);
}
});
it('DB-BOOT-004: accepts a Postgres database on its own', () => {
expect(() => validateEnvAtBoot({ TREK_DB_URL: 'postgresql://u:p@db:5432/trek?sslmode=require' })).not.toThrow();
});
it('DB-BOOT-005: refuses a pool size outside 1 to 100', () => {
expect(bootReport({ TREK_DB_POOL_MAX: '0' }).thrown).toMatch(/Invalid environment configuration/);
expect(() => validateEnvAtBoot({ TREK_DB_POOL_MAX: '20' })).not.toThrow();
});
});