bugfix - could not create more than one app

This commit is contained in:
Michael Shanks 2020-05-11 16:14:31 +01:00
parent 7d6046d021
commit 1a1d545178
2 changed files with 7 additions and 6 deletions

View File

@ -11,19 +11,17 @@ const { exec } = require("child_process")
module.exports = opts => { module.exports = opts => {
run(opts) run(opts)
console.log(chalk.green(`Budibase app ${opts.name} created!`))
} }
const run = async opts => { const run = async opts => {
console.log(opts)
try { try {
opts.dir = xPlatHomeDir(opts.dir) opts.dir = xPlatHomeDir(opts.dir)
console.log(resolve(opts.dir))
const bbconfig = dotenv.config({ path: resolve(opts.dir, ".env") }) const bbconfig = dotenv.config({ path: resolve(opts.dir, ".env") })
console.log(bbconfig) console.log(bbconfig)
await createAppInstance(opts) await createAppInstance(opts)
await createEmptyAppPackage(opts) await createEmptyAppPackage(opts)
exec(`cd ${join(opts.dir, opts.applicationId)} && npm install`) exec(`cd ${join(opts.dir, opts.applicationId)} && npm install`)
console.log(chalk.green(`Budibase app ${opts.name} created!`))
} catch (error) { } catch (error) {
console.error(chalk.red("Error creating new app", error)) console.error(chalk.red("Error creating new app", error))
} }
@ -40,6 +38,7 @@ const createAppInstance = async opts => {
await createApplication(createAppCtx) await createApplication(createAppCtx)
opts.applicationId = createAppCtx.body.id opts.applicationId = createAppCtx.body.id
console.log(chalk.green(`Application Created: ${createAppCtx.body.id}`))
await createInstance({ await createInstance({
params: { params: {
clientId: process.env.CLIENT_ID, clientId: process.env.CLIENT_ID,
@ -49,6 +48,7 @@ const createAppInstance = async opts => {
body: { name: `dev-${process.env.CLIENT_ID}` }, body: { name: `dev-${process.env.CLIENT_ID}` },
}, },
}) })
console.log(chalk.green(`Default Instance Created`))
} }
const createEmptyAppPackage = async opts => { const createEmptyAppPackage = async opts => {

View File

@ -1,10 +1,11 @@
const CouchDB = require("../../db") const CouchDB = require("../../db")
const uuid = require("uuid")
exports.create = async function(ctx) { exports.create = async function(ctx) {
const instanceName = ctx.request.body.name const instanceName = ctx.request.body.name
const instanceId = `app_${ctx.params.applicationId.substring(6)}_inst_${uuid.v4()}`
const { clientId, applicationId } = ctx.params const { clientId, applicationId } = ctx.params
const db = new CouchDB(instanceName) const db = new CouchDB(instanceId)
await db.put({ await db.put({
_id: "_design/database", _id: "_design/database",
metadata: { metadata: {
@ -31,7 +32,7 @@ exports.create = async function(ctx) {
const clientDatabaseId = `client-${clientId}` const clientDatabaseId = `client-${clientId}`
const clientDb = new CouchDB(clientDatabaseId) const clientDb = new CouchDB(clientDatabaseId)
const budibaseApp = await clientDb.get(applicationId) const budibaseApp = await clientDb.get(applicationId)
const instance = { id: instanceName, name: instanceName } const instance = { id: instanceId, name: instanceName }
budibaseApp.instances.push(instance) budibaseApp.instances.push(instance)
await clientDb.put(budibaseApp) await clientDb.put(budibaseApp)