budibase/packages/server/initialise/createInstanceDb.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

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) => {
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
}
}