2020-02-03 10:24:25 +01:00
|
|
|
const { initialiseData, setupDatastore } = require("@budibase/core")
|
|
|
|
const getDatabaseManager = require("../utilities/databaseManager")
|
|
|
|
const { applictionVersionPackage } = require("../utilities/createAppPackage")
|
|
|
|
const { determineVersionId } = require("../utilities/runtimePackages")
|
2019-07-07 10:03:37 +02:00
|
|
|
|
2019-07-09 08:29:50 +02:00
|
|
|
module.exports = async (context, datastoreModule, app, instance) => {
|
2020-02-03 10:24:25 +01:00
|
|
|
try {
|
|
|
|
const databaseManager = getDatabaseManager(
|
|
|
|
datastoreModule,
|
|
|
|
context.config.datastoreConfig
|
|
|
|
)
|
|
|
|
|
|
|
|
await databaseManager.createEmptyInstanceDb(app.id, instance.id)
|
|
|
|
|
|
|
|
const dbConfig = databaseManager.getInstanceDatastoreConfig(
|
|
|
|
app.id,
|
|
|
|
instance.id
|
|
|
|
)
|
|
|
|
|
|
|
|
const datastore = setupDatastore(datastoreModule.getDatastore(dbConfig))
|
|
|
|
|
|
|
|
const versionId = determineVersionId(instance.version)
|
|
|
|
|
|
|
|
const appPackage = await applictionVersionPackage(
|
|
|
|
context,
|
|
|
|
app.name,
|
|
|
|
versionId,
|
|
|
|
instance.key
|
|
|
|
)
|
|
|
|
|
|
|
|
await initialiseData(
|
|
|
|
datastore,
|
|
|
|
appPackage.appDefinition,
|
|
|
|
appPackage.accessLevels
|
|
|
|
)
|
|
|
|
|
|
|
|
return dbConfig
|
|
|
|
} catch (e) {
|
|
|
|
throw e
|
|
|
|
}
|
|
|
|
}
|