mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 03:50:30 +00:00
feat(db): choose the database engine from TREK_DB_URL
A port for the engine TREK runs on, without changing what it runs on. src/db/engine/ names the engine (SqliteEngine, PostgresEngine) and builds the MikroORM config from it; src/mikro-orm.config.ts exports that config for the CLI and the Nest container alike. Without TREK_DB_URL the config is the one it was: the shared SQLite driver on TREK_DB_FILE or data/travel.db. - TREK_DB_URL takes a postgres:// or postgresql:// URL and is masked in the boot report; TREK_DB_POOL_MAX sizes the pool (1 to 100, default 10). TREK_DB_URL beside TREK_DB_FILE, TREK_DB_JOURNAL_MODE or TREK_DB_SYNCHRONOUS refuses the boot as an ambiguous configuration. - MikroORM builds the pg pool from the URL's host, port, user, password and database and drops the rest of the query, so the engine reads sslmode and sslrootcert itself. require, verify-ca and verify-full all verify the server's certificate, as the pg driver reads them; a mode that would not verify, or a misspelt one, refuses. - Postgres cannot run TREK yet, so a boot with TREK_DB_URL is refused with that reason, in the boot check and again where the config is built, before anything connects. - @mikro-orm/postgresql moves to dependencies; pg is plain JavaScript. - lint:engine-dispatch (CI) holds the engine checks outside src/db/dialect/ and src/db/engine/ (isSqlite(, isPostgres(, an instanceof on a platform, a comparison on the engine's name) to a baseline that starts and stays empty.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import type { Options } from '@mikro-orm/core';
|
||||
|
||||
/** The databases TREK can be pointed at. MySQL/MariaDB are out of scope (server/CLAUDE.md). */
|
||||
type EngineId = 'sqlite' | 'postgres';
|
||||
|
||||
/**
|
||||
* One database engine: what the ORM needs to reach it and how to name it in a
|
||||
* log line. Code that differs by engine dispatches through this, or through
|
||||
* the helpers in `db/dialect/`, never through its own platform check
|
||||
* (`lint:engine-dispatch`).
|
||||
*
|
||||
* Free of Nest like every other file under `db/`: `src/db` does not import
|
||||
* `src/nest` (`lint:boundaries`).
|
||||
*/
|
||||
export interface DatabaseEngine {
|
||||
readonly id: EngineId;
|
||||
/** Whether this release can run TREK on the engine; `buildOrmConfig` refuses one that cannot. */
|
||||
readonly ready: boolean;
|
||||
/** For log lines and errors: the file path, or the URL without its password. */
|
||||
describe(): string;
|
||||
/** What MikroORM needs to reach the database: the driver and its target, the pool, driver options. */
|
||||
ormOptions(): Partial<Options>;
|
||||
}
|
||||
Reference in New Issue
Block a user