budibase/packages/server/utilities/createInstanceDb.js

33 lines
997 B
JavaScript
Raw Normal View History

const { common, getAppApis } = require("@budibase/core")
const { getDatabaseManager } = require("./databaseManager")
2019-06-07 13:02:48 +02:00
module.exports = async (productSetId, productId, versionId) => {
const databaseManager = getDatabaseManager(datastoreModule)
const masterDatastore = datastoreModule.getDatastore(
databaseManager.masterDatastoreConfig
)
2019-06-07 13:02:48 +02:00
const master = await getAppApis(masterDatastore)
2019-06-07 13:02:48 +02:00
const productSet = await master.recordApi.load(
common.joinKey("ProductSets", productSetId)
)
2019-06-07 13:02:48 +02:00
const prodcutSetDatastore = datastoreModule.getDatastore(
productSet.datastoreConfig
)
2019-06-07 13:02:48 +02:00
const productSetApis = await getAppApis(prodcutSetDatastore)
const product = await productSetApis.recordApi.load(
common.joinKey("Products", productId)
)
2019-06-07 13:02:48 +02:00
const version = await productSetApis.recordApi.load(
common.joinKey("Products", productId, "Versions", versionId)
)
const instance = await productSetApis.recordApi.getNew(
common.joinKey(product.key, "Versions")
)
}