1
0
Fork 0
mirror of synced 2024-09-14 08:18:31 +12:00
budibase/initialise/createMasterDb.js

55 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-04-06 04:30:29 +13:00
const {initialiseData,
getTemplateApi} = require("budibase-core");
const {newField, getDatabaseManager,
getApisWithFullAccess} = require("./helpers");
2019-03-20 10:45:21 +13:00
2019-04-06 04:30:29 +13:00
module.exports = async (datastoreModule, username, password) => {
const databaseManager = getDatabaseManager(datastoreModule);
const masterDbConfig = await databaseManager.createEmptyMasterDb();
const datastore = datastoreModule.getDatastore(masterDbConfig);
2019-03-20 10:45:21 +13:00
const templateApi = getTemplateApi();
const root = templateApi.getNewRootLevel();
const productSets = templateApi.getNewCollectionTemplate(root);
productSets.name = "ProductSets";
const productSet = templateApi.getNewRecordTemplate(productSets);
productSet.name = "ProductSet";
const newProductSetField = newField(templateApi, productSet);
newProductSetField("name", "string", true);
2019-04-06 04:30:29 +13:00
newProductSetField("dbRootConfig", "string");
2019-03-20 10:45:21 +13:00
const products = templateApi.getNewCollectionTemplate(productSet);
products.name = "Products";
const product = templateApi.getNewRecordTemplate(products);
product.name = "product";
const newProductField = newField(templateApi, product);
newProductField("name", "string", true);
newProductField("domain", "string", true);
2019-04-06 04:30:29 +13:00
newProductField("datastoreConfig", "string", true);
2019-03-20 10:45:21 +13:00
await initialiseData(datastore, {
heirarchy:root, actions:[], triggers:[]
});
2019-04-06 04:30:29 +13:00
const bb = await getApisWithFullAccess(datastore);
2019-03-20 10:45:21 +13:00
const fullAccess = bb.authApi.getNewAccessLevel();
fullAccess.permissions = bb.authApi.generateFullPermissions();
fullAccess.name = "Full Access";
await bb.authApi.saveAccessLevels([fullAccess]);
const seedUser = bb.authApi.getNewUser();
seedUser.name = username;
seedUser.accessLevels = ["Full Access"];
await bb.authApi.createUser(seedUser, password);
2019-04-06 04:30:29 +13:00
return masterDbConfig;
2019-03-20 10:45:21 +13:00
};