Merge branch 'dev' into chore/logging
This commit is contained in:
commit
f82668148c
122 changed files with 6026 additions and 14446 deletions
|
@ -1,13 +1,37 @@
|
|||
import { MikroORM } from '@mikro-orm/core';
|
||||
import { EntityManager, MikroORM } from '@mikro-orm/core';
|
||||
import config from './mikro-orm.config.js';
|
||||
import { EnvVars, getEnvVar } from './util/envvars.js';
|
||||
import { getLogger } from './logging/initalize.js';
|
||||
import { Logger } from 'winston';
|
||||
|
||||
export default async function initORM() {
|
||||
let orm: MikroORM | undefined;
|
||||
export async function initORM(testingMode: boolean = false) {
|
||||
const logger: Logger = getLogger();
|
||||
|
||||
logger.info('Initializing ORM');
|
||||
logger.debug('MikroORM config is', config);
|
||||
|
||||
await MikroORM.init(config);
|
||||
orm = await MikroORM.init(config(testingMode));
|
||||
// Update the database scheme if necessary and enabled.
|
||||
if (getEnvVar(EnvVars.DbUpdate)) {
|
||||
await orm.schema.updateSchema();
|
||||
} else {
|
||||
const diff = await orm.schema.getUpdateSchemaSQL();
|
||||
if (diff) {
|
||||
throw Error(
|
||||
'The database structure needs to be updated in order to fit the new database structure ' +
|
||||
'of the app. In order to do so automatically, set the environment variable DWENGO_DB_UPDATE to true. ' +
|
||||
'The following queries will then be executed:\n' +
|
||||
diff
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
export function forkEntityManager(): EntityManager {
|
||||
if (!orm) {
|
||||
throw Error(
|
||||
'Accessing the Entity Manager before the ORM is fully initialized.'
|
||||
);
|
||||
}
|
||||
return orm.em.fork();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue