From 4f549974ed47e4bc114bcaad47224d7264478921 Mon Sep 17 00:00:00 2001 From: Balu Babu Date: Thu, 14 Mar 2024 21:46:34 +0530 Subject: [PATCH] fix: reset infra-config bug (#3898) --- docker-compose.yml | 4 +-- .../src/infra-config/infra-config.service.ts | 27 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 62b36a367..b7f3d2f52 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -112,7 +112,7 @@ services: build: dockerfile: packages/hoppscotch-backend/Dockerfile context: . - target: dev + target: prod env_file: - ./.env restart: always @@ -122,7 +122,7 @@ services: - PORT=3000 volumes: # Uncomment the line below when modifying code. Only applicable when using the "dev" target. - - ./packages/hoppscotch-backend/:/usr/src/app + # - ./packages/hoppscotch-backend/:/usr/src/app - /usr/src/app/node_modules/ depends_on: hoppscotch-db: diff --git a/packages/hoppscotch-backend/src/infra-config/infra-config.service.ts b/packages/hoppscotch-backend/src/infra-config/infra-config.service.ts index a024d9f33..9b2aa8c7d 100644 --- a/packages/hoppscotch-backend/src/infra-config/infra-config.service.ts +++ b/packages/hoppscotch-backend/src/infra-config/infra-config.service.ts @@ -321,25 +321,28 @@ export class InfraConfigService implements OnModuleInit { * Reset all the InfraConfigs to their default values (from .env) */ async reset() { + // These are all the infra-configs that should not be reset + const RESET_EXCLUSION_LIST = [ + InfraConfigEnum.IS_FIRST_TIME_INFRA_SETUP, + InfraConfigEnum.ANALYTICS_USER_ID, + InfraConfigEnum.ALLOW_ANALYTICS_COLLECTION, + ]; try { const infraConfigDefaultObjs = await getDefaultInfraConfigs(); + const updatedInfraConfigDefaultObjs = infraConfigDefaultObjs.filter( + (p) => RESET_EXCLUSION_LIST.includes(p.name) === false, + ); await this.prisma.infraConfig.deleteMany({ - where: { name: { in: infraConfigDefaultObjs.map((p) => p.name) } }, + where: { + name: { + in: updatedInfraConfigDefaultObjs.map((p) => p.name), + }, + }, }); - // Hardcode t - const updatedInfraConfigDefaultObjs = infraConfigDefaultObjs.filter( - (obj) => obj.name !== InfraConfigEnum.IS_FIRST_TIME_INFRA_SETUP, - ); await this.prisma.infraConfig.createMany({ - data: [ - ...updatedInfraConfigDefaultObjs, - { - name: InfraConfigEnum.IS_FIRST_TIME_INFRA_SETUP, - value: 'true', - }, - ], + data: updatedInfraConfigDefaultObjs, }); stopApp();