From 38b880ac280690d6d91cef6b9f8dde980744ceed Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 18 Jun 2021 18:05:31 +0100 Subject: [PATCH] Fixing some issues I found with testing automations against external tables. --- .../app/[application]/data/table/_layout.svelte | 2 +- packages/server/src/api/routes/table.js | 2 +- packages/server/src/automations/triggers.js | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/data/table/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/data/table/_layout.svelte index 4cc0b7de0d..33378ffc7f 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/table/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/table/_layout.svelte @@ -8,7 +8,7 @@ // and this is the final url (i.e. no selectedTable) if ( !$leftover && - $tables.list.length > 0(!$tables.selected || !$tables.selected._id) + $tables.list.length > (!$tables.selected || !$tables.selected._id) ) { $goto(`./${$tables.list[0]._id}`) } diff --git a/packages/server/src/api/routes/table.js b/packages/server/src/api/routes/table.js index 381e0ecc2a..806caff6aa 100644 --- a/packages/server/src/api/routes/table.js +++ b/packages/server/src/api/routes/table.js @@ -17,7 +17,7 @@ function generateSaveValidator() { return joiValidator.body(Joi.object({ _id: Joi.string(), _rev: Joi.string(), - type: Joi.string().valid("table"), + type: Joi.string().valid("table", "internal", "external"), primaryDisplay: Joi.string(), schema: Joi.object().required(), name: Joi.string().required(), diff --git a/packages/server/src/automations/triggers.js b/packages/server/src/automations/triggers.js index 332710a3e4..4a4022e609 100644 --- a/packages/server/src/automations/triggers.js +++ b/packages/server/src/automations/triggers.js @@ -8,6 +8,8 @@ const { getAutomationParams } = require("../db/utils") const { coerce } = require("../utilities/rowProcessor") const { utils } = require("@budibase/auth/redis") const { JobQueues } = require("../constants") +const { isExternalTable, breakExternalTableId } = require("../integrations/utils") +const { getExternalTable } = require("../api/controllers/table/utils") const { opts } = utils.getRedisOptions() let automationQueue = new Queue(JobQueues.AUTOMATIONS, { redis: opts }) @@ -288,9 +290,15 @@ emitter.on("row:delete", async function (event) { async function fillRowOutput(automation, params) { let triggerSchema = automation.definition.trigger let tableId = triggerSchema.inputs.tableId - const db = new CouchDB(params.appId) try { - let table = await db.get(tableId) + let table + if (!isExternalTable(tableId)) { + const db = new CouchDB(params.appId) + table = await db.get(tableId) + } else { + const { datasourceId, tableName } = breakExternalTableId(tableId) + table = await getExternalTable(params.appId, datasourceId, tableName) + } let row = {} for (let schemaKey of Object.keys(table.schema)) { const paramValue = params[schemaKey]