feat: infra config key check added instead of count check
This commit is contained in:
committed by
Andrew Bastin
parent
2d7fb8e23a
commit
01fd27f81a
@@ -163,18 +163,20 @@ export async function getDefaultInfraConfigs(): Promise<
|
|||||||
export async function isInfraConfigTablePopulated(): Promise<boolean> {
|
export async function isInfraConfigTablePopulated(): Promise<boolean> {
|
||||||
const prisma = new PrismaService();
|
const prisma = new PrismaService();
|
||||||
try {
|
try {
|
||||||
const infraConfigCountInDB = await prisma.infraConfig.count();
|
const dbInfraConfigs = await prisma.infraConfig.findMany();
|
||||||
const infraConfigCountShouldBe = getDefaultInfraConfigs().length;
|
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(
|
console.log(
|
||||||
'Infra Config table is not populated with all entries. Populating now...',
|
'Infra Config table is not populated with all entries. Populating now...',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return isPopulated;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ export class InfraConfigService implements OnModuleInit {
|
|||||||
*/
|
*/
|
||||||
async initializeInfraConfigTable() {
|
async initializeInfraConfigTable() {
|
||||||
try {
|
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);
|
const enumValues = Object.values(InfraConfigEnum);
|
||||||
|
|
||||||
// Fetch the default values (value in .env) for configs to be saved in 'infra_config' table
|
// Fetch the default values (value in .env) for configs to be saved in 'infra_config' table
|
||||||
const infraConfigDefaultObjs = await getDefaultInfraConfigs();
|
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) {
|
if (enumValues.length !== infraConfigDefaultObjs.length) {
|
||||||
throw new Error(INFRA_CONFIG_NOT_LISTED);
|
throw new Error(INFRA_CONFIG_NOT_LISTED);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user