Fixing some issues I found with testing automations against external tables.

This commit is contained in:
mike12345567 2021-06-18 18:05:31 +01:00
parent 3475273f80
commit 3f1b95218e
3 changed files with 12 additions and 4 deletions

View File

@ -8,7 +8,7 @@
// and this is the final url (i.e. no selectedTable) // and this is the final url (i.e. no selectedTable)
if ( if (
!$leftover && !$leftover &&
$tables.list.length > 0(!$tables.selected || !$tables.selected._id) $tables.list.length > (!$tables.selected || !$tables.selected._id)
) { ) {
$goto(`./${$tables.list[0]._id}`) $goto(`./${$tables.list[0]._id}`)
} }

View File

@ -17,7 +17,7 @@ function generateSaveValidator() {
return joiValidator.body(Joi.object({ return joiValidator.body(Joi.object({
_id: Joi.string(), _id: Joi.string(),
_rev: Joi.string(), _rev: Joi.string(),
type: Joi.string().valid("table"), type: Joi.string().valid("table", "internal", "external"),
primaryDisplay: Joi.string(), primaryDisplay: Joi.string(),
schema: Joi.object().required(), schema: Joi.object().required(),
name: Joi.string().required(), name: Joi.string().required(),

View File

@ -8,6 +8,8 @@ const { getAutomationParams } = require("../db/utils")
const { coerce } = require("../utilities/rowProcessor") const { coerce } = require("../utilities/rowProcessor")
const { utils } = require("@budibase/auth/redis") const { utils } = require("@budibase/auth/redis")
const { JobQueues } = require("../constants") const { JobQueues } = require("../constants")
const { isExternalTable, breakExternalTableId } = require("../integrations/utils")
const { getExternalTable } = require("../api/controllers/table/utils")
const { opts } = utils.getRedisOptions() const { opts } = utils.getRedisOptions()
let automationQueue = new Queue(JobQueues.AUTOMATIONS, { redis: opts }) let automationQueue = new Queue(JobQueues.AUTOMATIONS, { redis: opts })
@ -288,9 +290,15 @@ emitter.on("row:delete", async function (event) {
async function fillRowOutput(automation, params) { async function fillRowOutput(automation, params) {
let triggerSchema = automation.definition.trigger let triggerSchema = automation.definition.trigger
let tableId = triggerSchema.inputs.tableId let tableId = triggerSchema.inputs.tableId
const db = new CouchDB(params.appId)
try { 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 = {} let row = {}
for (let schemaKey of Object.keys(table.schema)) { for (let schemaKey of Object.keys(table.schema)) {
const paramValue = params[schemaKey] const paramValue = params[schemaKey]