2019-06-28 23:59:27 +02:00
|
|
|
const {
|
|
|
|
initialiseData,
|
|
|
|
setupDatastore
|
|
|
|
} = require("budibase-core");
|
|
|
|
const constructHierarchy = require("../utilities/constructHierarchy");
|
2019-07-01 23:49:13 +02:00
|
|
|
const getDatabaseManager = require("../utilities/databaseManager");
|
2019-06-28 23:59:27 +02:00
|
|
|
const masterDbAppDefinition = require("../appPackages/master/appDefinition.json");
|
|
|
|
|
|
|
|
module.exports = async (datastoreModule, rootDatastoreConfig, appId, instanceId) => {
|
|
|
|
try {
|
|
|
|
|
|
|
|
const databaseManager = getDatabaseManager(
|
|
|
|
datastoreModule, rootDatastoreConfig);
|
|
|
|
|
|
|
|
await databaseManager.createEmptyInstanceDb(
|
|
|
|
appId, instanceId);
|
|
|
|
|
|
|
|
const dbConfig = databaseManager.getInstanceDatastoreConfig(
|
|
|
|
appId, instanceId);
|
|
|
|
|
|
|
|
const datastore = setupDatastore(
|
|
|
|
datastoreModule.getDatastore(dbConfig));
|
|
|
|
|
|
|
|
await initialiseData(datastore,
|
|
|
|
constructHierarchy(masterDbAppDefinition));
|
|
|
|
|
|
|
|
return dbConfig;
|
|
|
|
|
|
|
|
} catch(e) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|