mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 21:33:19 +00:00
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:
@@ -0,0 +1,32 @@
|
||||
import mikroOrmConfig from '../mikro-orm.config';
|
||||
import type { AnyOrm } from './orm';
|
||||
import { SharedSqliteDriver } from './orm-driver';
|
||||
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> {
|
||||
if (mikroOrmConfig.driver !== SharedSqliteDriver) {
|
||||
throw new Error('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 },
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user