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
+36
View File
@@ -0,0 +1,36 @@
import { buildOrmConfig, resolveEngine } from '../../src/db/engine';
import { MikroORM } from '@mikro-orm/core';
/**
* Brings the template database TREK_DB_URL names to the current schema, the
* way a first boot on an empty Postgres database does: the engine's own
* bootstrap (baseline, the migrations after its cut, seeders), with no
* pre-migrate copy, since the database is new.
*/
async function main(): Promise<void> {
const engine = resolveEngine();
if (engine.id !== 'postgres') throw new Error('build-template.ts runs on the Postgres engine only (TREK_DB_URL).');
const config = buildOrmConfig(engine);
const orm = await MikroORM.init({
...config,
// As src/db/standalone-orm.ts: the bootstrap runs SQL and seeders, which
// need no entity metadata.
entities: [],
entitiesTs: [],
discovery: { warnWhenNoEntities: false },
migrations: { ...config.migrations, silent: true },
});
try {
await engine.schemaBootstrap(orm, { snapshot: false });
process.stdout.write(`[test-db] Postgres template ready: ${engine.describe()}\n`);
} finally {
await orm.close(true);
}
}
main().catch((err: unknown) => {
process.stderr.write(
`[test-db] failed to build the Postgres template: ${err instanceof Error ? err.stack : String(err)}\n`,
);
process.exit(1);
});