feat: add initial database migration

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2023-10-08 15:08:57 +02:00 committed by Philip Molares
parent 09698579a7
commit f8f198f9c9
7 changed files with 1082 additions and 5 deletions

28
backend/src/ormconfig.ts Normal file
View file

@ -0,0 +1,28 @@
/*
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { DataSource } from 'typeorm';
import { AppModule } from './app.module';
import { AppConfig } from './config/app.config';
import { Loglevel } from './config/loglevel.enum';
import { ConsoleLoggerService } from './logger/console-logger.service';
async function buildDataSource(): Promise<DataSource> {
// We create a new app instance to let it discover entities
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
logger: new ConsoleLoggerService({ loglevel: Loglevel.TRACE } as AppConfig),
});
const dataSource = app.get(DataSource);
// The migration CLI does not want an existing connection
await dataSource.destroy();
return dataSource;
}
export default buildDataSource();