2019-06-28 23:59:27 +02:00
|
|
|
const {
|
|
|
|
initialiseData,
|
2019-10-11 18:14:23 +02:00
|
|
|
setupDatastore
|
2019-09-10 07:14:45 +02:00
|
|
|
} = require("@budibase/core");
|
2019-07-01 23:49:13 +02:00
|
|
|
const getDatabaseManager = require("../utilities/databaseManager");
|
2019-07-07 10:03:37 +02:00
|
|
|
const { applictionVersionPackage } = require("../utilities/createAppPackage");
|
2019-10-11 18:14:23 +02:00
|
|
|
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) => {
|
2019-06-28 23:59:27 +02:00
|
|
|
try {
|
|
|
|
|
|
|
|
const databaseManager = getDatabaseManager(
|
2019-07-09 08:29:50 +02:00
|
|
|
datastoreModule,
|
|
|
|
context.config.datastoreConfig);
|
2019-06-28 23:59:27 +02:00
|
|
|
|
|
|
|
await databaseManager.createEmptyInstanceDb(
|
2019-07-07 10:03:37 +02:00
|
|
|
app.id, instance.id);
|
2019-06-28 23:59:27 +02:00
|
|
|
|
|
|
|
const dbConfig = databaseManager.getInstanceDatastoreConfig(
|
2019-07-07 10:03:37 +02:00
|
|
|
app.id, instance.id);
|
2019-06-28 23:59:27 +02:00
|
|
|
|
|
|
|
const datastore = setupDatastore(
|
2019-07-07 10:03:37 +02:00
|
|
|
datastoreModule.getDatastore(dbConfig));
|
|
|
|
|
2019-10-11 18:14:23 +02:00
|
|
|
const versionId = determineVersionId(instance.version);
|
2019-07-07 10:03:37 +02:00
|
|
|
|
2019-07-09 08:29:50 +02:00
|
|
|
const appPackage = await applictionVersionPackage(
|
|
|
|
context, app.name, versionId, instance.key
|
2019-07-07 10:03:37 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
await initialiseData(
|
|
|
|
datastore,
|
|
|
|
appPackage.appDefinition,
|
|
|
|
appPackage.accessLevels);
|
2019-06-28 23:59:27 +02:00
|
|
|
|
|
|
|
return dbConfig;
|
|
|
|
|
|
|
|
} catch(e) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|