feat(backend): Databank initialiseren
Verbinding met databank aangemaakt, eerste entities toegevoegd, centrale API aangemaakt om omgevingsvariabelen voor onze app op te vragen.
This commit is contained in:
parent
c07bb959cf
commit
62a278a6e0
8 changed files with 86 additions and 10 deletions
|
|
@ -1,6 +1,19 @@
|
|||
import { MikroORM } from '@mikro-orm/core';
|
||||
import config from './mikro-orm.config.js';
|
||||
import {EnvVars, getEnvVar} from "./util/envvars";
|
||||
|
||||
export default async function initORM() {
|
||||
await MikroORM.init(config);
|
||||
const orm = await MikroORM.init(config);
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue