mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 02:56:10 +00:00
526437926a
npm run test:pg --workspace=server (vitest.pg.config.ts) runs every suite that boots the app through buildApp() on the real database module against Postgres, each test file on its own copy of one template database the engine's bootstrap migrates once per run. TREK_TEST_DB_URL names the server; without it the lane fails instead of passing on nothing. The CI job 'Server: Postgres Tests' runs it on a postgres:17 service and is part of ci-ok. tests/postgres/ holds what only Postgres needs proving: - PARITY-PG: MikroORM's comparator finds nothing between the bootstrapped database and the entities. What it reports that changes nothing (key columns it would make nullable, defaults and checks Postgres spells its own way, the hand-ported triggers) is proven so: the spelling statements run in a rolled-back transaction and every default and check must read the same after, and every ported trigger must exist. - the write lock: concurrent read-then-insert units of work never see the same count, and counts are numbers; a search ignores case. tours-hike and tours-plan-types stay on SQLite only: they move a faked setTimeout on until a tool call ends, which a database over the network does not finish within.
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
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);
|
|
});
|