From a6a7b7795da5f01325a70b03fc9f7c379bcaafb8 Mon Sep 17 00:00:00 2001 From: rozetko Date: Wed, 20 Mar 2019 15:36:31 +0300 Subject: [PATCH] Fix 0.3.2-beta migration script --- server/src/migrations/0.3.2-beta.ts | 30 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/server/src/migrations/0.3.2-beta.ts b/server/src/migrations/0.3.2-beta.ts index b27d862..a5766d3 100644 --- a/server/src/migrations/0.3.2-beta.ts +++ b/server/src/migrations/0.3.2-beta.ts @@ -12,19 +12,25 @@ export async function convertPanelUrlToPanelId() { const panelUrlRegex = /^(.+)\/d\/(\w+)\/.+panelId=(\d+)/; const newPanelUrlRegex = /^(.+)\/dashboard\/(\w+).+panelId=(\d+)/; - const updatedAnalyticUnits = analyticUnits.map(analyticUnit => { - const parsedPanelUrl = analyticUnit.panelUrl.match(panelUrlRegex) || analyticUnit.panelUrl.match(newPanelUrlRegex); - const grafanaUrl = parsedPanelUrl[1]; - const dashboardId = parsedPanelUrl[2]; - const oldPanelId = parsedPanelUrl[3]; - const panelId = `${dashboardId}/${oldPanelId}`; + const updatedAnalyticUnits = analyticUnits + .map(analyticUnit => { + const parsedPanelUrl = analyticUnit.panelUrl.match(panelUrlRegex) || analyticUnit.panelUrl.match(newPanelUrlRegex); + if(parsedPanelUrl === null) { + console.log(`Cannot parse url: ${analyticUnit.panelUrl}`); + return null; + } + const grafanaUrl = parsedPanelUrl[1]; + const dashboardId = parsedPanelUrl[2]; + const oldPanelId = parsedPanelUrl[3]; + const panelId = `${dashboardId}/${oldPanelId}`; - return { - _id: analyticUnit._id, - grafanaUrl, - panelId - }; - }); + return { + _id: analyticUnit._id, + grafanaUrl, + panelId + }; + }) + .filter(analyticUnit => analyticUnit !== null); console.log(updatedAnalyticUnits); await updatedAnalyticUnits.forEach(analyticUnit => db.updateOne(analyticUnit._id, {