bugfix - could not create more than one app
This commit is contained in:
parent
7d6046d021
commit
1a1d545178
|
@ -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 => {
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue