diff --git a/packages/hoppscotch-backend/src/infra-config/helper.ts b/packages/hoppscotch-backend/src/infra-config/helper.ts index 76a8acf83..3cc68006f 100644 --- a/packages/hoppscotch-backend/src/infra-config/helper.ts +++ b/packages/hoppscotch-backend/src/infra-config/helper.ts @@ -163,18 +163,20 @@ export async function getDefaultInfraConfigs(): Promise< export async function isInfraConfigTablePopulated(): Promise { const prisma = new PrismaService(); try { - const infraConfigCountInDB = await prisma.infraConfig.count(); - const infraConfigCountShouldBe = getDefaultInfraConfigs().length; + const dbInfraConfigs = await prisma.infraConfig.findMany(); + const infraConfigDefaultObjs = getDefaultInfraConfigs(); - const isPopulated = infraConfigCountInDB === infraConfigCountShouldBe; + const propsRemainingToInsert = infraConfigDefaultObjs.filter( + (p) => !dbInfraConfigs.find((e) => e.name === p.name), + ); - if (!isPopulated) { + if (propsRemainingToInsert.length > 0) { console.log( 'Infra Config table is not populated with all entries. Populating now...', ); } - return isPopulated; + return true; } catch (error) { return false; } 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 d747e2b13..a9c8042e0 100644 --- a/packages/hoppscotch-backend/src/infra-config/infra-config.service.ts +++ b/packages/hoppscotch-backend/src/infra-config/infra-config.service.ts @@ -51,13 +51,13 @@ export class InfraConfigService implements OnModuleInit { */ async initializeInfraConfigTable() { try { - // Get all the 'names' of the properties to be saved in the 'infra_config' table + // Get all the 'names' of the properties from ENUM to be saved in the 'infra_config' table const enumValues = Object.values(InfraConfigEnum); // Fetch the default values (value in .env) for configs to be saved in 'infra_config' table const infraConfigDefaultObjs = await getDefaultInfraConfigs(); - // Check if all the 'names' are listed in the default values + // Cross-check if all the 'names' are listed in the default-values-list and ENUM at the same time if (enumValues.length !== infraConfigDefaultObjs.length) { throw new Error(INFRA_CONFIG_NOT_LISTED); }