Skip to content

Commit

Permalink
Handle missing db relations when importing baseline (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
erssebaggala authored Nov 14, 2019
1 parent f089760 commit 9537c72
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
35 changes: 28 additions & 7 deletions background/baseline.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`;
}
const result = await queryHelper.runQuery(sql);

try{
const result = await queryHelper.runQuery(sql);
}catch(e){
log.error(e);
}
}

/*
Expand Down Expand Up @@ -222,7 +227,11 @@ ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
}

//console.log(sql);
const result = await queryHelper.runQuery(sql);
try{
const result = await queryHelper.runQuery(sql);
}catch(e){
log.error(e);
}
}


Expand All @@ -244,7 +253,6 @@ WHERE
t1.data->>'BSC_NAME' IS NOT NULL
AND TRIM(t1.data->>'BSC_NAME') != ''
AND t1.data->>'${parameter}' IS NOT NULL
t1.data->>'BSC_NAME' IS NOT NULL
GROUP BY
t1.data->>'BSC_NAME',
t1.data->>'${parameter}'
Expand Down Expand Up @@ -304,7 +312,12 @@ ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`;
}
const result = await queryHelper.runQuery(sql);

try{
const result = await queryHelper.runQuery(sql);
}catch(e){
log.error(e);
}
}

async function computeZTEBaselineScore(tech, mo, parameter){
Expand Down Expand Up @@ -361,7 +374,12 @@ ON CONFLICT ON CONSTRAINT unq_scores DO UPDATE SET
score=EXCLUDED.score + scores.score
`;
}
const result = await queryHelper.runQuery(sql);

try{
const result = await queryHelper.runQuery(sql);
}catch(e){
log.error(e);
}
}


Expand Down Expand Up @@ -645,12 +663,15 @@ async function uploadUserBaseline(baselineFile, truncate){
}

let values = paramIndices.map(v => {
return v === vendorIndex ? dataRow[v].toUpperCase() : dataRow[v];
const value = v === vendorIndex ? dataRow[v].toUpperCase() : dataRow[v];

//limit value length to 200
return value.toString().slice(0,200);
});
const sql = `INSERT INTO baseline."configuration"
(${parameterList.join(",")})
VALUES
('${values.join("','")}')
($$${values.join("$$,$$")}$$)
ON CONFLICT ON CONSTRAINT unq_configuration DO UPDATE
SET
${updatePhrase.join(",")}
Expand Down
2 changes: 1 addition & 1 deletion db/migrations/1567621482558_Create-baseline-entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports.up = async (pgm) => {
technology: {type: "varchar(20)", notNull: true},
mo: {type: "varchar(100)", notNull: true},
parameter: {type: "varchar(300)", notNull: true},
baseline: {type: "varchar(200)"}, //manually provided baseline value
baseline: {type: "varchar(300)"}, //manually provided baseline value
extra_fields: {type: "JSON"},
created_at: "createdAt",
modified_at: "createdAt",
Expand Down

0 comments on commit 9537c72

Please sign in to comment.