From d3c104d3f5a4aa21a74c0065724bfb0cd782d81e Mon Sep 17 00:00:00 2001 From: Amin Latifi Date: Mon, 4 Nov 2024 18:22:35 +0330 Subject: [PATCH] Run migrations only by the job server --- src/config.ts | 3 +++ src/orm.ts | 3 ++- src/server/bootstrap.ts | 5 +---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/config.ts b/src/config.ts index 2e7e6a98c..b02eb2835 100644 --- a/src/config.ts +++ b/src/config.ts @@ -121,4 +121,7 @@ class Config { const config = new Config(process.env); +export const isGraphQlMode = config.get('GRAPHQL_MODE') === 'true'; +export const isJobMode = config.get('JOB_MODE') === 'true'; + export default config; diff --git a/src/orm.ts b/src/orm.ts index 9625e97fd..c23c44dbd 100644 --- a/src/orm.ts +++ b/src/orm.ts @@ -1,6 +1,6 @@ import { DataSource } from 'typeorm'; import { PostgresConnectionCredentialsOptions } from 'typeorm/driver/postgres/PostgresConnectionCredentialsOptions'; -import config from './config'; +import config, { isJobMode } from './config'; import { CronJob } from './entities/CronJob'; import { getEntities } from './entities/entities'; import { redisConfig } from './redis'; @@ -57,6 +57,7 @@ export class AppDataSource { }, }, poolSize, + migrationsRun: isJobMode, extra: { maxWaitingClients: 10, evictionRunIntervalMillis: 500, diff --git a/src/server/bootstrap.ts b/src/server/bootstrap.ts index a86a54cd9..a99d77d2c 100644 --- a/src/server/bootstrap.ts +++ b/src/server/bootstrap.ts @@ -18,7 +18,7 @@ import bodyParser from 'body-parser'; import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js'; import { ApolloServerPluginLandingPageDisabled } from '@apollo/server/plugin/disabled'; import { ApolloServerErrorCode } from '@apollo/server/errors'; -import config from '../config'; +import config, { isGraphQlMode, isJobMode } from '../config'; import { handleStripeWebhook } from '../utils/stripe'; import createSchema from './createSchema'; import SentryLogger from '../sentryLogger'; @@ -83,9 +83,6 @@ export async function bootstrap() { try { logger.debug('bootstrap() has been called', new Date()); - const isGraphQlMode = config.get('GRAPHQL_MODE') === 'true'; - const isJobMode = config.get('JOB_MODE') === 'true'; - logger.info('isGraphQlMode: ', isGraphQlMode); logger.info('isJobMode: ', isJobMode);