mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 01:36:29 -05:00
fix(migrations): use migration file extension according to runtime
We need to use .ts only if we run inside ts-node or other tools that use it. In all other cases, we need to refer to the .js migration files. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
f8f198f9c9
commit
10776de54f
2 changed files with 26 additions and 1 deletions
|
@ -38,6 +38,7 @@ import { WebsocketModule } from './realtime/websocket/websocket.module';
|
||||||
import { RevisionsModule } from './revisions/revisions.module';
|
import { RevisionsModule } from './revisions/revisions.module';
|
||||||
import { SessionModule } from './sessions/session.module';
|
import { SessionModule } from './sessions/session.module';
|
||||||
import { UsersModule } from './users/users.module';
|
import { UsersModule } from './users/users.module';
|
||||||
|
import { detectTsNode } from './utils/detectTsNode';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
|
@ -70,7 +71,11 @@ const routes: Routes = [
|
||||||
autoLoadEntities: true,
|
autoLoadEntities: true,
|
||||||
logging: true,
|
logging: true,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
migrations: [`**/migrations/${databaseConfig.type}-*{.ts,.js}`],
|
migrations: [
|
||||||
|
`**/migrations/${databaseConfig.type}-*.${
|
||||||
|
detectTsNode() ? 'ts' : 'js'
|
||||||
|
}`,
|
||||||
|
],
|
||||||
migrationsRun: true,
|
migrationsRun: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
20
backend/src/utils/detectTsNode.ts
Normal file
20
backend/src/utils/detectTsNode.ts
Normal file
|
@ -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
|
||||||
|
}
|
Loading…
Reference in a new issue