upgrade data - hooked up to server & builder

This commit is contained in:
Michael Shanks 2020-03-24 10:58:15 +00:00
parent 9ee1132185
commit 3429311d5e
5 changed files with 12 additions and 7 deletions

View File

@ -74,6 +74,9 @@ export const getPotentialReferenceIndexes = (hierarchy, record) =>
), ),
]) ])
export const isIndex = hierarchyFunctions.isIndex
export const isRecord = hierarchyFunctions.isRecord
export const getDefaultTypeOptions = type => export const getDefaultTypeOptions = type =>
!type ? {} : allTypes[type].getDefaultOptions() !type ? {} : allTypes[type].getDefaultOptions()

View File

@ -24,20 +24,23 @@ import { cloneApp } from "../appInitialise/cloneApp"
import { initialiseData } from "../appInitialise/initialiseData" import { initialiseData } from "../appInitialise/initialiseData"
import { initialiseChildrenForNode } from "../recordApi/initialiseChildren" import { initialiseChildrenForNode } from "../recordApi/initialiseChildren"
import { initialiseNewIndex } from "./initialiseNewIndex" 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 => { 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 diff = diffHierarchy(app.hierarchy, newHierarchy)
const changeActions = gatherChangeActions(diff) const changeActions = gatherChangeActions(diff)
if (changeActions.length === 0) return if (changeActions.length === 0) return
newHierarchy = constructHierarchy(newHierarchy)
const newApp = newHierarchy && cloneApp(app, { const newApp = newHierarchy && cloneApp(app, {
hierarchy: newHierarchy hierarchy: newHierarchy
}) })
await doUpgrade(app, newApp, changeActions) await doUpgrade(app, newApp, changeActions)
await saveApplicationHierarchy(newApp)(newHierarchy) await _saveApplicationHierarchy(newApp.datastore, newHierarchy)
} }
const gatherChangeActions = (diff) => const gatherChangeActions = (diff) =>

View File

@ -18,7 +18,7 @@ const lookupField = require("./lookupField")
const getRecord = require("./getRecord") const getRecord = require("./getRecord")
const deleteRecord = require("./deleteRecord") const deleteRecord = require("./deleteRecord")
const saveAppHierarchy = require("./saveAppHierarchy") const saveAppHierarchy = require("./saveAppHierarchy")
const upgradeData = require("./saveAppHierarchy") const upgradeData = require("./upgradeData")
module.exports = { module.exports = {
authenticate, authenticate,

View File

@ -155,7 +155,6 @@ module.exports = (config, app) => {
} }
} }
}) })
.get("/_builder/api/:appname/componentlibrary", async ctx => { .get("/_builder/api/:appname/componentlibrary", async ctx => {
const info = await componentLibraryInfo( const info = await componentLibraryInfo(
config, config,
@ -323,4 +322,4 @@ module.exports = (config, app) => {
.post("/:appname/api/apphierarchy", routeHandlers.saveAppHierarchy) .post("/:appname/api/apphierarchy", routeHandlers.saveAppHierarchy)
return router return router
} }

View File

@ -8,7 +8,7 @@
"build": "cd appPackages/_master && yarn && cd ../testApp && yarn && cd ../testApp2 && yarn", "build": "cd appPackages/_master && yarn && cd ../testApp && yarn && cd ../testApp2 && yarn",
"initialise": "node ./initialise/initialiseBudibase init -d ./myapps -c contributors -u admin -p admin", "initialise": "node ./initialise/initialiseBudibase init -d ./myapps -c contributors -u admin -p admin",
"budi": "node ../cli/bin/budi", "budi": "node ../cli/bin/budi",
"dev:builder": "node index" "dev:builder": "node index --enable-source-maps"
}, },
"keywords": [ "keywords": [
"budibase" "budibase"