From 1a1d54517873e1d829e88c9dcf92758e89865b5b Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Mon, 11 May 2020 16:14:31 +0100 Subject: [PATCH] bugfix - could not create more than one app --- packages/cli/src/commands/new/newHandler.js | 6 +++--- packages/server/src/api/controllers/instance.js | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/commands/new/newHandler.js b/packages/cli/src/commands/new/newHandler.js index 36297ed664..f79a46f9fb 100644 --- a/packages/cli/src/commands/new/newHandler.js +++ b/packages/cli/src/commands/new/newHandler.js @@ -11,19 +11,17 @@ const { exec } = require("child_process") module.exports = opts => { run(opts) - console.log(chalk.green(`Budibase app ${opts.name} created!`)) } const run = async opts => { - console.log(opts) try { opts.dir = xPlatHomeDir(opts.dir) - console.log(resolve(opts.dir)) const bbconfig = dotenv.config({ path: resolve(opts.dir, ".env") }) console.log(bbconfig) await createAppInstance(opts) await createEmptyAppPackage(opts) exec(`cd ${join(opts.dir, opts.applicationId)} && npm install`) + console.log(chalk.green(`Budibase app ${opts.name} created!`)) } catch (error) { console.error(chalk.red("Error creating new app", error)) } @@ -40,6 +38,7 @@ const createAppInstance = async opts => { await createApplication(createAppCtx) opts.applicationId = createAppCtx.body.id + console.log(chalk.green(`Application Created: ${createAppCtx.body.id}`)) await createInstance({ params: { clientId: process.env.CLIENT_ID, @@ -49,6 +48,7 @@ const createAppInstance = async opts => { body: { name: `dev-${process.env.CLIENT_ID}` }, }, }) + console.log(chalk.green(`Default Instance Created`)) } const createEmptyAppPackage = async opts => { diff --git a/packages/server/src/api/controllers/instance.js b/packages/server/src/api/controllers/instance.js index d359ee81d7..7e0e0eef1b 100644 --- a/packages/server/src/api/controllers/instance.js +++ b/packages/server/src/api/controllers/instance.js @@ -1,10 +1,11 @@ const CouchDB = require("../../db") +const uuid = require("uuid") exports.create = async function(ctx) { const instanceName = ctx.request.body.name - + const instanceId = `app_${ctx.params.applicationId.substring(6)}_inst_${uuid.v4()}` const { clientId, applicationId } = ctx.params - const db = new CouchDB(instanceName) + const db = new CouchDB(instanceId) await db.put({ _id: "_design/database", metadata: { @@ -31,7 +32,7 @@ exports.create = async function(ctx) { const clientDatabaseId = `client-${clientId}` const clientDb = new CouchDB(clientDatabaseId) const budibaseApp = await clientDb.get(applicationId) - const instance = { id: instanceName, name: instanceName } + const instance = { id: instanceId, name: instanceName } budibaseApp.instances.push(instance) await clientDb.put(budibaseApp)