From 7c21645799da3b873b1ba1f0ca440c52b7a12345 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 8 Nov 2021 13:06:25 +0100 Subject: [PATCH 1/3] fix revert on unpublished app --- packages/server/src/api/controllers/dev.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/server/src/api/controllers/dev.js b/packages/server/src/api/controllers/dev.js index c43de7f553..ed58b8048b 100644 --- a/packages/server/src/api/controllers/dev.js +++ b/packages/server/src/api/controllers/dev.js @@ -82,6 +82,13 @@ exports.revert = async ctx => { const db = new CouchDB(productionAppId, { skip_setup: true }) const info = await db.info() if (info.error) throw info.error + const deploymentDoc = await db.get(DocumentTypes.DEPLOYMENTS) + if ( + !deploymentDoc.history || + Object.keys(deploymentDoc.history).length === 0 + ) { + throw new Error("No deployments for app") + } } catch (err) { return ctx.throw(400, "App has not yet been deployed") } From 035879d5151d4fdfbe2dbaac1562e5b13265428d Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 8 Nov 2021 15:26:07 +0100 Subject: [PATCH 2/3] adding check to make sure production db isn't created on sync --- packages/server/src/api/controllers/application.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index e2e42c20f9..ff4955f530 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -329,6 +329,19 @@ exports.sync = async ctx => { ctx.throw(400, "This action cannot be performed for production apps") } 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({ source: prodAppId, target: appId, From 9fb811a8dae903f739e709b9077fef0ed11865a1 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 8 Nov 2021 15:26:44 +0100 Subject: [PATCH 3/3] change message when app not deployed --- packages/server/src/api/controllers/application.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index ff4955f530..f27efff29e 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -337,7 +337,7 @@ exports.sync = async ctx => { } catch (err) { // the database doesn't exist. Don't replicate ctx.body = { - message: "App sync completed successfully.", + message: "App sync not required, app not deployed.", } return }