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
@@ -0,0 +1,29 @@
/**
* DatabaseEngineModule: one engine per container, shared by every injector.
*/
import {
DatabaseEngineModule,
DATABASE_ENGINE,
DATABASE_SETTINGS,
} from '../../../../src/nest/database/database-engine.module';
import { Test } from '@nestjs/testing';
import { describe, expect, it } from 'vitest';
describe('DatabaseEngineModule', () => {
it('ENGINE-DI-001: provides one engine instance, so state an engine keeps is the same wherever it is injected', async () => {
const moduleRef = await Test.createTestingModule({ imports: [DatabaseEngineModule] }).compile();
const engine = moduleRef.get(DATABASE_ENGINE);
expect(moduleRef.get(DATABASE_ENGINE)).toBe(engine);
expect(engine.id).toBe('sqlite');
});
it('ENGINE-DI-002: the settings are read from the environment once and the engine is resolved from them', async () => {
const moduleRef = await Test.createTestingModule({ imports: [DatabaseEngineModule] }).compile();
const settings = moduleRef.get(DATABASE_SETTINGS);
expect(settings.engine).toBe('sqlite');
expect(moduleRef.get(DATABASE_SETTINGS)).toBe(settings);
});
});