Merge pull request #3259 from Budibase/fix/external-db-usage

Fixing issues with external tables in the cloud (MySQL Google Cloud issue)
This commit is contained in:
Michael Drury 2021-11-08 12:20:27 +00:00 committed by GitHub
commit 19464064bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 2 deletions

View File

@ -2,6 +2,10 @@ const CouchDB = require("../db")
const usageQuota = require("../utilities/usageQuota") const usageQuota = require("../utilities/usageQuota")
const env = require("../environment") const env = require("../environment")
const { getTenantId } = require("@budibase/auth/tenancy") const { getTenantId } = require("@budibase/auth/tenancy")
const {
isExternalTable,
isRowId: isExternalRowId,
} = require("../integrations/utils")
// tenants without limits // tenants without limits
const EXCLUDED_TENANTS = ["bb", "default", "bbtest", "bbstaging"] const EXCLUDED_TENANTS = ["bb", "default", "bbtest", "bbstaging"]
@ -46,14 +50,24 @@ module.exports = async (ctx, next) => {
} }
// post request could be a save of a pre-existing entry // post request could be a save of a pre-existing entry
if (ctx.request.body && ctx.request.body._id && ctx.request.body._rev) { if (ctx.request.body && ctx.request.body._id && ctx.request.body._rev) {
const usageId = ctx.request.body._id
try { try {
if (ctx.appId) { if (ctx.appId) {
const db = new CouchDB(ctx.appId) const db = new CouchDB(ctx.appId)
await db.get(ctx.request.body._id) await db.get(usageId)
} }
return next() return next()
} catch (err) { } catch (err) {
ctx.throw(404, `${ctx.request.body._id} does not exist`) if (
isExternalTable(usageId) ||
(ctx.request.body.tableId &&
isExternalTable(ctx.request.body.tableId)) ||
isExternalRowId(usageId)
) {
return next()
} else {
ctx.throw(404, `${usageId} does not exist`)
}
} }
} }