From 3429311d5e0a11721b377d157cc6c2871ad968ee Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Tue, 24 Mar 2020 10:58:15 +0000 Subject: [PATCH] upgrade data - hooked up to server & builder --- packages/builder/src/common/core.js | 3 +++ packages/core/src/templateApi/upgradeData.js | 9 ++++++--- packages/server/middleware/routeHandlers/index.js | 2 +- packages/server/middleware/routers.js | 3 +-- packages/server/package.json | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/common/core.js b/packages/builder/src/common/core.js index 18da89033b..dbdd186aa3 100644 --- a/packages/builder/src/common/core.js +++ b/packages/builder/src/common/core.js @@ -74,6 +74,9 @@ export const getPotentialReferenceIndexes = (hierarchy, record) => ), ]) +export const isIndex = hierarchyFunctions.isIndex +export const isRecord = hierarchyFunctions.isRecord + export const getDefaultTypeOptions = type => !type ? {} : allTypes[type].getDefaultOptions() diff --git a/packages/core/src/templateApi/upgradeData.js b/packages/core/src/templateApi/upgradeData.js index 6da0eb1a9f..bce39f5381 100644 --- a/packages/core/src/templateApi/upgradeData.js +++ b/packages/core/src/templateApi/upgradeData.js @@ -24,20 +24,23 @@ import { cloneApp } from "../appInitialise/cloneApp" import { initialiseData } from "../appInitialise/initialiseData" import { initialiseChildrenForNode } from "../recordApi/initialiseChildren" import { initialiseNewIndex } from "./initialiseNewIndex" -import { saveApplicationHierarchy } from "../templateApi/saveApplicationHierarchy" +import { _saveApplicationHierarchy } from "../templateApi/saveApplicationHierarchy" +import { getApplicationDefinition } from "../templateApi/getApplicationDefinition" export const upgradeData = app => async newHierarchy => { + const currentAppDef = await getApplicationDefinition(app.datastore)() + app.hierarchy = currentAppDef.hierarchy + newHierarchy = constructHierarchy(newHierarchy) const diff = diffHierarchy(app.hierarchy, newHierarchy) const changeActions = gatherChangeActions(diff) if (changeActions.length === 0) return - newHierarchy = constructHierarchy(newHierarchy) const newApp = newHierarchy && cloneApp(app, { hierarchy: newHierarchy }) await doUpgrade(app, newApp, changeActions) - await saveApplicationHierarchy(newApp)(newHierarchy) + await _saveApplicationHierarchy(newApp.datastore, newHierarchy) } const gatherChangeActions = (diff) => diff --git a/packages/server/middleware/routeHandlers/index.js b/packages/server/middleware/routeHandlers/index.js index ea91c4ba12..b8e7fa5624 100644 --- a/packages/server/middleware/routeHandlers/index.js +++ b/packages/server/middleware/routeHandlers/index.js @@ -18,7 +18,7 @@ const lookupField = require("./lookupField") const getRecord = require("./getRecord") const deleteRecord = require("./deleteRecord") const saveAppHierarchy = require("./saveAppHierarchy") -const upgradeData = require("./saveAppHierarchy") +const upgradeData = require("./upgradeData") module.exports = { authenticate, diff --git a/packages/server/middleware/routers.js b/packages/server/middleware/routers.js index 122240d701..00e2deff9c 100644 --- a/packages/server/middleware/routers.js +++ b/packages/server/middleware/routers.js @@ -155,7 +155,6 @@ module.exports = (config, app) => { } } }) - .get("/_builder/api/:appname/componentlibrary", async ctx => { const info = await componentLibraryInfo( config, @@ -323,4 +322,4 @@ module.exports = (config, app) => { .post("/:appname/api/apphierarchy", routeHandlers.saveAppHierarchy) return router -} \ No newline at end of file +} diff --git a/packages/server/package.json b/packages/server/package.json index 63e030be23..5a5b34d25f 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -8,7 +8,7 @@ "build": "cd appPackages/_master && yarn && cd ../testApp && yarn && cd ../testApp2 && yarn", "initialise": "node ./initialise/initialiseBudibase init -d ./myapps -c contributors -u admin -p admin", "budi": "node ../cli/bin/budi", - "dev:builder": "node index" + "dev:builder": "node index --enable-source-maps" }, "keywords": [ "budibase"