mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
fix(db): count every spelling of an engine check in lint:engine-dispatch
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.
This commit is contained in:
@@ -2,6 +2,7 @@ import { readEnv } from '../../app-config';
|
||||
import type { DbEngineSettings } from '../../app-config/db-settings';
|
||||
import type { DbSettings } from '../../app-config/derive';
|
||||
import { ALL_ENTITIES } from '../entities';
|
||||
import { SharedSqliteDriver } from '../orm-driver';
|
||||
import type { DatabaseEngine } from './engine';
|
||||
import { PostgresEngine } from './postgres/postgres-engine';
|
||||
import { SqliteEngine } from './sqlite/sqlite-engine';
|
||||
@@ -34,6 +35,17 @@ export function postgresTarget(db: DbSettings): { url: string; binDir: string |
|
||||
return { url: db.url, binDir: db.pgBinDir, poolMax: db.poolMax };
|
||||
}
|
||||
|
||||
/**
|
||||
* Refuses an ORM config that does not run on the SQLite engine, with
|
||||
* `refusal` as the error. For the code that exists only for SQLite (the test
|
||||
* schema snapshot), which must say so instead of starting a SQLite ORM on
|
||||
* another engine's options; the check on the driver stays here, in the
|
||||
* engine port, like every other question about the engine.
|
||||
*/
|
||||
export function assertSqliteOrmConfig(config: Options, refusal: string): void {
|
||||
if (config.driver !== SharedSqliteDriver) throw new Error(refusal);
|
||||
}
|
||||
|
||||
/**
|
||||
* The MikroORM config for `engine`: what every engine shares (entities,
|
||||
* migrations, seeders) and what the engine adds. `src/mikro-orm.config.ts`
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import mikroOrmConfig from '../mikro-orm.config';
|
||||
import { assertSqliteOrmConfig } from './engine';
|
||||
import type { AnyOrm } from './orm';
|
||||
import { SharedSqliteDriver } from './orm-driver';
|
||||
import { MikroORM as SqliteMikroORM } from '@mikro-orm/sqlite';
|
||||
|
||||
/**
|
||||
@@ -12,9 +12,10 @@ import { MikroORM as SqliteMikroORM } from '@mikro-orm/sqlite';
|
||||
* SQLite driver's, so a config that names another engine is refused.
|
||||
*/
|
||||
export function createStandaloneOrm(): Promise<AnyOrm> {
|
||||
if (mikroOrmConfig.driver !== SharedSqliteDriver) {
|
||||
throw new Error('createStandaloneOrm builds the SQLite schema snapshot; unset TREK_DB_URL to run it.');
|
||||
}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user