mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 19:16:08 +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:
@@ -1,30 +1,14 @@
|
||||
import { resolveDbPath } from './db/db-path';
|
||||
import { ALL_ENTITIES } from './db/entities';
|
||||
import { SharedSqliteDriver } from './db/orm-driver';
|
||||
import { Migrator } from '@mikro-orm/migrations';
|
||||
import { SeedManager } from '@mikro-orm/seeder';
|
||||
import { defineConfig } from '@mikro-orm/sqlite';
|
||||
import { buildOrmConfig, resolveEngine } from './db/engine';
|
||||
|
||||
export default defineConfig({
|
||||
entities: ALL_ENTITIES,
|
||||
extensions: [Migrator, SeedManager],
|
||||
// Reuses the connection db/database.ts owns rather than opening a second one.
|
||||
// See orm-driver.ts — with `:memory:` in tests, a second connection would be a
|
||||
// second, empty database.
|
||||
driver: SharedSqliteDriver,
|
||||
migrations: {
|
||||
path: 'dist/db/migrations',
|
||||
pathTs: 'src/db/migrations',
|
||||
snapshot: false,
|
||||
},
|
||||
seeder: {
|
||||
path: 'dist/db/seeders',
|
||||
pathTs: 'src/db/seeders',
|
||||
defaultSeeder: 'DatabaseSeeder',
|
||||
},
|
||||
// Same resolution database.ts uses: `:memory:` under test, TREK_DB_FILE when
|
||||
// set, else data/travel.db. The driver above ignores it for the connection
|
||||
// itself, but the CLI and the migrator's logging still read it, and naming a
|
||||
// different file here than the one actually open is a trap.
|
||||
dbName: resolveDbPath(),
|
||||
});
|
||||
/**
|
||||
* The MikroORM config for the CLI and the Nest container alike: the engine
|
||||
* `TREK_DB_URL` names (the SQLite file by default) and what every engine shares
|
||||
* (`db/engine/index.ts`).
|
||||
*
|
||||
* Built at module level, not from `DATABASE_ENGINE`, because the MikroORM CLI
|
||||
* loads this file without Nest. Only the engine's options come from it, and
|
||||
* those are plain values with no state, so it and the container's engine agree
|
||||
* on the database. The state an engine keeps (Postgres's reopen hook) exists
|
||||
* only on the container's instance.
|
||||
*/
|
||||
export default buildOrmConfig(resolveEngine());
|
||||
|
||||
Reference in New Issue
Block a user