2019-06-08 01:18:10 +12:00
|
|
|
const {initialiseData, setupDatastore,
|
|
|
|
getTemplateApi} = require("budibase-core");
|
2019-06-14 21:05:46 +12:00
|
|
|
const getDatabaseManager = require("../utilities/databaseManager");
|
|
|
|
const {getApisForUser, getApisWithFullAccess} = require("../utilities/budibaseApi");
|
2019-06-08 01:18:10 +12:00
|
|
|
const masterDbAppDefinition = require("../appPackages/master/appDefinition.json");
|
|
|
|
const masterDbAccessLevels = require("../appPackages/master/access_levels.json");
|
2019-06-26 09:48:22 +12:00
|
|
|
const { masterAppPackage } = require("../utilities/createAppPackage");
|
2019-06-08 01:18:10 +12:00
|
|
|
|
|
|
|
module.exports = async (datastoreModule, rootConfig, username, password) => {
|
|
|
|
try {
|
|
|
|
const databaseManager = getDatabaseManager(datastoreModule, rootConfig);
|
|
|
|
|
|
|
|
await databaseManager.createEmptyMasterDb();
|
|
|
|
const masterDbConfig = databaseManager.masterDatastoreConfig;
|
|
|
|
const datastore = setupDatastore(
|
|
|
|
datastoreModule.getDatastore(masterDbConfig)
|
|
|
|
);
|
|
|
|
|
|
|
|
const templateApi = getTemplateApi({datastore});
|
|
|
|
|
|
|
|
await initialiseData(datastore, {
|
2019-06-26 09:48:22 +12:00
|
|
|
hierarchy:templateApi.constructHierarchy(masterDbAppDefinition.hierarchy),
|
2019-06-08 01:18:10 +12:00
|
|
|
actions:masterDbAppDefinition.actions,
|
|
|
|
triggers:masterDbAppDefinition.triggers
|
|
|
|
});
|
|
|
|
|
2019-06-26 09:48:22 +12:00
|
|
|
const bbMaster = await getApisWithFullAccess(
|
|
|
|
datastore, masterAppPackage());
|
2019-06-08 01:18:10 +12:00
|
|
|
await bbMaster.authApi.saveAccessLevels(masterDbAccessLevels);
|
|
|
|
const user = bbMaster.authApi.getNewUser();
|
|
|
|
user.name = username;
|
|
|
|
user.accessLevels= ["owner"];
|
|
|
|
await bbMaster.authApi.createUser(user, password);
|
|
|
|
|
2019-06-26 09:48:22 +12:00
|
|
|
return await getApisForUser(datastore, masterAppPackage(), username, password);
|
2019-06-08 01:18:10 +12:00
|
|
|
} catch(e) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|