From 12abe4adcc3e4affdcb511f124c9d322336aa606 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Tue, 26 Apr 2022 17:13:45 +0100 Subject: [PATCH 1/3] Bypass couch db when using tenancy middleware --- packages/backend-core/src/context/index.js | 9 +++++++-- packages/backend-core/src/environment.js | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/backend-core/src/context/index.js b/packages/backend-core/src/context/index.js index acf8434d3b..b6b6f2380c 100644 --- a/packages/backend-core/src/context/index.js +++ b/packages/backend-core/src/context/index.js @@ -71,7 +71,9 @@ exports.doInTenant = (tenantId, task) => { // set the tenant id if (!opts.existing) { cls.setOnContext(ContextKeys.TENANT_ID, tenantId) - exports.setGlobalDB(tenantId) + if (env.USE_COUCH) { + exports.setGlobalDB(tenantId) + } } try { @@ -80,7 +82,9 @@ exports.doInTenant = (tenantId, task) => { } finally { const using = cls.getFromContext(ContextKeys.IN_USE) if (!using || using <= 1) { - await closeDB(exports.getGlobalDB()) + if (env.USE_COUCH) { + await closeDB(exports.getGlobalDB()) + } // clear from context now that database is closed/task is finished cls.setOnContext(ContextKeys.TENANT_ID, null) cls.setOnContext(ContextKeys.GLOBAL_DB, null) @@ -167,6 +171,7 @@ exports.doInAppContext = (appId, task) => { exports.updateTenantId = tenantId => { cls.setOnContext(ContextKeys.TENANT_ID, tenantId) + exports.setGlobalDB(tenantId) } exports.updateAppId = async appId => { diff --git a/packages/backend-core/src/environment.js b/packages/backend-core/src/environment.js index 527760c1ca..8a92e39469 100644 --- a/packages/backend-core/src/environment.js +++ b/packages/backend-core/src/environment.js @@ -30,9 +30,18 @@ module.exports = { COOKIE_DOMAIN: process.env.COOKIE_DOMAIN, PLATFORM_URL: process.env.PLATFORM_URL, TENANT_FEATURE_FLAGS: process.env.TENANT_FEATURE_FLAGS, + USE_COUCH: process.env.USE_COUCH || true, isTest, _set(key, value) { process.env[key] = value module.exports[key] = value }, } + +// clean up any environment variable edge cases +for (let [key, value] of Object.entries(module.exports)) { + // handle the edge case of "0" to disable an environment variable + if (value === "0") { + module.exports[key] = 0 + } +} From d736e558f9a45d77d9fd9958190de580d8a2069b Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Tue, 26 Apr 2022 17:55:33 +0100 Subject: [PATCH 2/3] Update pro install script to checkout base branch only when feature branch doesn't exist --- scripts/pro/install.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/pro/install.sh b/scripts/pro/install.sh index cd1682d651..6a388dc190 100755 --- a/scripts/pro/install.sh +++ b/scripts/pro/install.sh @@ -20,8 +20,12 @@ if [[ -d "budibase-pro" ]]; then # Try to checkout the matching pro branch git checkout $BRANCH - # Try to checkout the matching pro base (master or develop) branch - git checkout $BASE_BRANCH + + if [[ $? == "1" ]] && [[ $BASE_BRANCH ]]; then + # There is no matching branch, try to match the base branch + git checkout $BASE_BRANCH + fi + # If neither branch exists continue with default branch 'develop' git pull From bcee277acb2683eaab5520e6bb0dc840f406e7d7 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 26 Apr 2022 18:28:37 +0100 Subject: [PATCH 3/3] Fixing issue with db init as part of the jest require. --- .../src/middleware/tests/currentapp.spec.js | 12 ++++++++---- packages/server/yarn.lock | 18 +++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/server/src/middleware/tests/currentapp.spec.js b/packages/server/src/middleware/tests/currentapp.spec.js index bee07cbf91..85447581cc 100644 --- a/packages/server/src/middleware/tests/currentapp.spec.js +++ b/packages/server/src/middleware/tests/currentapp.spec.js @@ -1,10 +1,14 @@ mockAuthWithNoCookie() mockWorker() -jest.mock("@budibase/backend-core/db", () => ({ - ...jest.requireActual("@budibase/backend-core/db"), - dbExists: () => true, -})) +jest.mock("@budibase/backend-core/db", () => { + const coreDb = jest.requireActual("@budibase/backend-core/db") + coreDb.init() + return { + ...coreDb, + dbExists: () => true, + } +}) function mockWorker() { jest.mock("../../utilities/workerRequests", () => ({ diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index 13cedfadb5..2354f7a339 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -1014,10 +1014,10 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/backend-core@1.0.105-alpha.42": - version "1.0.105-alpha.42" - resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.105-alpha.42.tgz#732daf9234312261c91158303459bb02f95656e0" - integrity sha512-takLU6UcUVVzcF8EZEazxmY37Th8DwjG8CEtBrlYZn+yrAO+27XixOws72P+6Xr9IxGyAWxMpIQ8E5uZi6Zl9w== +"@budibase/backend-core@1.0.105-alpha.43": + version "1.0.105-alpha.43" + resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.105-alpha.43.tgz#9790310c2758867b958f6c4a8313e9fbd2a4df4e" + integrity sha512-pS2VmSPi/i+r4EjsG4WszQ2VeIssu+ugVgl1O+oXA8/acPMWSWv1ct3JKrckz3sdKiSjllXhy+B4ZPvfN1Ezpg== dependencies: "@techpass/passport-openidconnect" "^0.3.0" aws-sdk "^2.901.0" @@ -1087,12 +1087,12 @@ svelte-flatpickr "^3.2.3" svelte-portal "^1.0.0" -"@budibase/pro@1.0.105-alpha.42": - version "1.0.105-alpha.42" - resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.105-alpha.42.tgz#b616b24d9008c268f87b532b89493670d5a0a915" - integrity sha512-ibiJRm+22B4t8XZVkDQz8RU8Jd3XSS0M0K8vLRqdFaB632Vt/dnnMx6GbUvurjSfqxsa72R2+jNOME64oUl0Gg== +"@budibase/pro@1.0.105-alpha.43": + version "1.0.105-alpha.43" + resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.105-alpha.43.tgz#0f90aa8570d789b8a69acf3895b6af036e32cc75" + integrity sha512-fz9JbHcWMsu2lHt7rH6HZqx6SosKjwKF2CUH3FMQgtQqCjJfe58GIPXgLh/eLT8O8Eq2F46HzRjABlqMUFjQSw== dependencies: - "@budibase/backend-core" "1.0.105-alpha.42" + "@budibase/backend-core" "1.0.105-alpha.43" node-fetch "^2.6.1" "@budibase/standard-components@^0.9.139":