From 8fd7c36a25ae679dad29ca13e64e6e668c03ef96 Mon Sep 17 00:00:00 2001 From: Yassine R Date: Tue, 12 Sep 2023 19:13:25 +0200 Subject: [PATCH] fix(typeorm): update migration flag --- .../services/_postgres/EXECUTE_MIGRATIONS.const.ts | 7 +++++++ .../services/_postgres/PG_CONNECT_OPTIONS.const.ts | 7 +------ packages/backend/src/database/services/_postgres/index.ts | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 packages/backend/src/database/services/_postgres/EXECUTE_MIGRATIONS.const.ts diff --git a/packages/backend/src/database/services/_postgres/EXECUTE_MIGRATIONS.const.ts b/packages/backend/src/database/services/_postgres/EXECUTE_MIGRATIONS.const.ts new file mode 100644 index 0000000000..d525001420 --- /dev/null +++ b/packages/backend/src/database/services/_postgres/EXECUTE_MIGRATIONS.const.ts @@ -0,0 +1,7 @@ +import { domifaConfig } from "../../../config"; +import { isCronEnabled } from "../../../config/services/isCronEnabled.service"; + +export const EXECUTE_MIGRATIONS = + ((domifaConfig().envId === "preprod" || domifaConfig().envId === "prod") && + isCronEnabled()) || + domifaConfig().envId === "local"; diff --git a/packages/backend/src/database/services/_postgres/PG_CONNECT_OPTIONS.const.ts b/packages/backend/src/database/services/_postgres/PG_CONNECT_OPTIONS.const.ts index 7076560fe7..561321885b 100644 --- a/packages/backend/src/database/services/_postgres/PG_CONNECT_OPTIONS.const.ts +++ b/packages/backend/src/database/services/_postgres/PG_CONNECT_OPTIONS.const.ts @@ -2,13 +2,8 @@ import { PostgresConnectionOptions } from "typeorm/driver/postgres/PostgresConne import { domifaConfig } from "../../../config"; import { appLogger } from "../../../util"; import { CustomTypeOrmLogger } from "../../../util/CustomTypeOrmLogger"; -import { isCronEnabled } from "../../../config/services/isCronEnabled.service"; const isTypescriptMode = __filename.split(".").pop() === "ts"; // if current file extension is "ts": use src/*.ts files, eles use dist/*.js files -const executeMigrations = - ((domifaConfig().envId === "preprod" || domifaConfig().envId === "prod") && - isCronEnabled()) || - domifaConfig().envId === "local"; let connectOptionsPaths: Pick< PostgresConnectionOptions, @@ -53,7 +48,7 @@ export const PG_CONNECT_OPTIONS: PostgresConnectionOptions = { type: "postgres", synchronize: false, migrationsTransactionMode: "each", - migrationsRun: executeMigrations, + migrationsRun: true, host: domifaConfig().postgres.host, port: domifaConfig().postgres.port, username: domifaConfig().postgres.username, diff --git a/packages/backend/src/database/services/_postgres/index.ts b/packages/backend/src/database/services/_postgres/index.ts index 4f7e8ce62a..7b21f381f0 100644 --- a/packages/backend/src/database/services/_postgres/index.ts +++ b/packages/backend/src/database/services/_postgres/index.ts @@ -1,5 +1,6 @@ // @index('./*', f => `export * from '${f.path}'`) export * from "./appTypeormManager.service"; +export * from "./EXECUTE_MIGRATIONS.const"; export * from "./PG_CONNECT_OPTIONS.const"; export * from "./PG_MIGRATION_CONFIG.const"; export * from "./pgRepository.service";