mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 21:33:19 +00:00
9eeb59997e
The gate matched only isSqlite(/isPostgres(, instanceof on a platform class and a comparison on a property named engine or id. A destructured engine name, the literal on the left, a switch over the engine, instanceof on a driver class and a comparison with a driver class all passed with an empty baseline, and standalone-orm.ts already held one such check. The regex now matches every one of them, the guard in standalone-orm.ts moves into the engine port as assertSqliteOrmConfig, and the advice names where a check belongs.
34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
import mikroOrmConfig from '../mikro-orm.config';
|
|
import { assertSqliteOrmConfig } from './engine';
|
|
import type { AnyOrm } from './orm';
|
|
import { MikroORM as SqliteMikroORM } from '@mikro-orm/sqlite';
|
|
|
|
/**
|
|
* An ORM instance outside Nest, for the vitest global setup that builds the
|
|
* schema snapshot. Production uses the container-owned one from
|
|
* `MikroOrmModule.forRoot()` instead of creating a second.
|
|
*
|
|
* SQLite only: the snapshot is the SQLite schema and the init below is the
|
|
* SQLite driver's, so a config that names another engine is refused.
|
|
*/
|
|
export function createStandaloneOrm(): Promise<AnyOrm> {
|
|
assertSqliteOrmConfig(
|
|
mikroOrmConfig,
|
|
'createStandaloneOrm builds the SQLite schema snapshot; unset TREK_DB_URL to run it.',
|
|
);
|
|
return SqliteMikroORM.init({
|
|
...mikroOrmConfig,
|
|
// Entity discovery is skipped deliberately. Migrations and seeders are raw
|
|
// SQL and need no metadata, and the global setup that calls this runs as ESM
|
|
// in vitest's main process, where discovering `*.entity.ts` fails on Node's
|
|
// extensionless import resolution.
|
|
entities: [],
|
|
entitiesTs: [],
|
|
discovery: { warnWhenNoEntities: false },
|
|
// The migrator's per-migration progress log is production boot output; the
|
|
// global setup already reports the snapshot in one line of its own, and a
|
|
// failing migration still throws.
|
|
migrations: { ...mikroOrmConfig.migrations, silent: true },
|
|
});
|
|
}
|