From d7ef5e606cbcd581cde8eb58228f02a1ea46f59d Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 11 Nov 2021 17:13:35 +0000 Subject: [PATCH] Fixing issue where deleted datasources wouldn't clear out queries. --- packages/builder/src/stores/backend/datasources.js | 1 + packages/server/src/api/controllers/datasource.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/stores/backend/datasources.js b/packages/builder/src/stores/backend/datasources.js index 91719ae9b7..7810c3a950 100644 --- a/packages/builder/src/stores/backend/datasources.js +++ b/packages/builder/src/stores/backend/datasources.js @@ -95,6 +95,7 @@ export function createDatasourcesStore() { return { list: sources, selected: null } }) + await queries.fetch() return response }, removeSchemaError: () => { diff --git a/packages/server/src/api/controllers/datasource.js b/packages/server/src/api/controllers/datasource.js index 643e822a36..009baec9e0 100644 --- a/packages/server/src/api/controllers/datasource.js +++ b/packages/server/src/api/controllers/datasource.js @@ -119,8 +119,16 @@ exports.destroy = async function (ctx) { const db = new CouchDB(ctx.appId) // Delete all queries for the datasource - const rows = await db.allDocs(getQueryParams(ctx.params.datasourceId, null)) - await db.bulkDocs(rows.rows.map(row => ({ ...row.doc, _deleted: true }))) + const queries = await db.allDocs( + getQueryParams(ctx.params.datasourceId, null) + ) + await db.bulkDocs( + queries.rows.map(row => ({ + _id: row.id, + _rev: row.value.rev, + _deleted: true, + })) + ) // delete the datasource await db.remove(ctx.params.datasourceId, ctx.params.revId)