@ -105,12 +105,6 @@ async function createInstance(template) {
if ( ! ok ) {
throw "Error loading database dump from template."
}
try {
const response = await db . get ( DocumentTypes . APP_METADATA )
_ rev = response . _ rev
} catch ( err ) {
_ rev = null
}
} else {
// create the users table
await db . put ( USERS_TABLE_SCHEMA )
@ -121,7 +115,7 @@ async function createInstance(template) {
await createRoutingView ( appId )
await createAllSearchIndex ( appId )
return { _ id : appId , _ rev }
return { _ id : appId }
}
exports . fetch = async function ( ctx ) {
@ -188,11 +182,21 @@ exports.create = async function (ctx) {
instanceConfig . file = ctx . request . files . templateFile
}
const instance = await createInstance ( instanceConfig )
const appId = instance . _ id
const url = await getAppUrlIfNotInUse ( ctx )
const appId = instance . _ id
const db = new CouchDB ( appId )
let _ rev
try {
// if template there will be an existing doc
const existing = await db . get ( DocumentTypes . APP_METADATA )
_ rev = existing . _ rev
} catch ( err ) {
// nothing to do
}
const newApplication = {
_ id : DocumentTypes . APP_METADATA ,
_ rev ,
appId : instance . _ id ,
type : "app" ,
version : packageJson . version ,
@ -204,11 +208,7 @@ exports.create = async function (ctx) {
updatedAt : new Date ( ) . toISOString ( ) ,
createdAt : new Date ( ) . toISOString ( ) ,
}
if ( instance . _ rev ) {
newApplication . _ rev = instance . _ rev
}
const instanceDb = new CouchDB ( appId )
await instanceDb . put ( newApplication )
await db . put ( newApplication , { force : true } )
await createEmptyAppPackage ( ctx , newApplication )
/* istanbul ignore next */