adding check to make sure production db isn't created on sync

This commit is contained in:
Martin McKeaveney 2021-11-08 15:26:07 +01:00
parent 7c21645799
commit 035879d515
1 changed files with 13 additions and 0 deletions

View File

@ -329,6 +329,19 @@ exports.sync = async ctx => {
ctx.throw(400, "This action cannot be performed for production apps") ctx.throw(400, "This action cannot be performed for production apps")
} }
const prodAppId = getDeployedAppID(appId) const prodAppId = getDeployedAppID(appId)
try {
const prodDb = new CouchDB(prodAppId, { skip_setup: true })
const info = await prodDb.info()
if (info.error) throw info.error
} catch (err) {
// the database doesn't exist. Don't replicate
ctx.body = {
message: "App sync completed successfully.",
}
return
}
const replication = new Replication({ const replication = new Replication({
source: prodAppId, source: prodAppId,
target: appId, target: appId,