diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 02416dd57..170d2a012 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -38,6 +38,7 @@ import { WebsocketModule } from './realtime/websocket/websocket.module'; import { RevisionsModule } from './revisions/revisions.module'; import { SessionModule } from './sessions/session.module'; import { UsersModule } from './users/users.module'; +import { detectTsNode } from './utils/detectTsNode'; const routes: Routes = [ { @@ -70,7 +71,11 @@ const routes: Routes = [ autoLoadEntities: true, logging: true, logger: logger, - migrations: [`**/migrations/${databaseConfig.type}-*{.ts,.js}`], + migrations: [ + `**/migrations/${databaseConfig.type}-*.${ + detectTsNode() ? 'ts' : 'js' + }`, + ], migrationsRun: true, }; }, diff --git a/backend/src/utils/detectTsNode.ts b/backend/src/utils/detectTsNode.ts new file mode 100644 index 000000000..e866ae1fe --- /dev/null +++ b/backend/src/utils/detectTsNode.ts @@ -0,0 +1,20 @@ +/* + * SPDX-FileCopyrightText: 2018 Martin Adámek + * + * SPDX-License-Identifier: MIT + */ + +/** + * Stolen from https://github.com/mikro-orm/mikro-orm/blob/20179ec839def5f8144e56f3a6bc89131f7e72a4/packages/core/src/utils/Utils.ts#L689 + */ +export function detectTsNode(): boolean { + return ( + process.argv[0].endsWith('ts-node') || // running via ts-node directly + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore TS7053 + !!process[Symbol.for('ts-node.register.instance')] || // check if internal ts-node symbol exists + !!process.env.TS_JEST || // check if ts-jest is used (works only with v27.0.4+) + process.argv.slice(1).some((arg) => arg.includes('ts-node')) || // registering ts-node runner + (require.extensions && !!require.extensions['.ts']) + ); // check if the extension is registered +}