Browse Source

Fix 0.3.2-beta migration script

pull/1/head
rozetko 5 years ago
parent
commit
a6a7b7795d
  1. 30
      server/src/migrations/0.3.2-beta.ts

30
server/src/migrations/0.3.2-beta.ts

@ -12,19 +12,25 @@ export async function convertPanelUrlToPanelId() {
const panelUrlRegex = /^(.+)\/d\/(\w+)\/.+panelId=(\d+)/; const panelUrlRegex = /^(.+)\/d\/(\w+)\/.+panelId=(\d+)/;
const newPanelUrlRegex = /^(.+)\/dashboard\/(\w+).+panelId=(\d+)/; const newPanelUrlRegex = /^(.+)\/dashboard\/(\w+).+panelId=(\d+)/;
const updatedAnalyticUnits = analyticUnits.map(analyticUnit => { const updatedAnalyticUnits = analyticUnits
const parsedPanelUrl = analyticUnit.panelUrl.match(panelUrlRegex) || analyticUnit.panelUrl.match(newPanelUrlRegex); .map(analyticUnit => {
const grafanaUrl = parsedPanelUrl[1]; const parsedPanelUrl = analyticUnit.panelUrl.match(panelUrlRegex) || analyticUnit.panelUrl.match(newPanelUrlRegex);
const dashboardId = parsedPanelUrl[2]; if(parsedPanelUrl === null) {
const oldPanelId = parsedPanelUrl[3]; console.log(`Cannot parse url: ${analyticUnit.panelUrl}`);
const panelId = `${dashboardId}/${oldPanelId}`; return null;
}
const grafanaUrl = parsedPanelUrl[1];
const dashboardId = parsedPanelUrl[2];
const oldPanelId = parsedPanelUrl[3];
const panelId = `${dashboardId}/${oldPanelId}`;
return { return {
_id: analyticUnit._id, _id: analyticUnit._id,
grafanaUrl, grafanaUrl,
panelId panelId
}; };
}); })
.filter(analyticUnit => analyticUnit !== null);
console.log(updatedAnalyticUnits); console.log(updatedAnalyticUnits);
await updatedAnalyticUnits.forEach(analyticUnit => db.updateOne(analyticUnit._id, { await updatedAnalyticUnits.forEach(analyticUnit => db.updateOne(analyticUnit._id, {

Loading…
Cancel
Save