diff --git a/packages/backend-core/src/db/utils.ts b/packages/backend-core/src/db/utils.ts index 321ebd7f58..baf4a27914 100644 --- a/packages/backend-core/src/db/utils.ts +++ b/packages/backend-core/src/db/utils.ts @@ -2,7 +2,8 @@ import { newid } from "../hashing" import { DEFAULT_TENANT_ID, Configs } from "../constants" import env from "../environment" import { SEPARATOR, DocumentType, UNICODE_MAX, ViewName } from "./constants" -import { getTenantId, getGlobalDBName, getGlobalDB } from "../tenancy" +import { getTenantId, getGlobalDB } from "../context" +import { getGlobalDBName } from "../tenancy/utils" import fetch from "node-fetch" import { doWithDB, allDbs } from "./index" import { getCouchInfo } from "./pouch" diff --git a/packages/backend-core/src/db/views.ts b/packages/backend-core/src/db/views.ts index 5086cb499a..de313e8190 100644 --- a/packages/backend-core/src/db/views.ts +++ b/packages/backend-core/src/db/views.ts @@ -1,5 +1,5 @@ import { DocumentType, ViewName, DeprecatedViews, SEPARATOR } from "./utils" -import { getGlobalDB } from "../tenancy" +import { getGlobalDB } from "../context" import { StaticDatabases } from "./constants" import { doWithDB } from "./" @@ -256,5 +256,5 @@ export const queryGlobalView = async ( if (!db) { db = getGlobalDB() as PouchDB.Database } - return queryView(viewName, params, db, CreateFuncByName) + return queryView(viewName, params, db, CreateFuncByName, opts) } diff --git a/packages/backend-core/src/tenancy/index.ts b/packages/backend-core/src/tenancy/index.ts index e0006abab2..d1ccbbf001 100644 --- a/packages/backend-core/src/tenancy/index.ts +++ b/packages/backend-core/src/tenancy/index.ts @@ -1,9 +1,11 @@ import * as context from "../context" import * as tenancy from "./tenancy" +import * as utils from "./utils" const pkg = { ...context, ...tenancy, + ...utils, } export = pkg diff --git a/packages/backend-core/src/tenancy/tenancy.ts b/packages/backend-core/src/tenancy/tenancy.ts index bd66772b52..b28d098a0d 100644 --- a/packages/backend-core/src/tenancy/tenancy.ts +++ b/packages/backend-core/src/tenancy/tenancy.ts @@ -1,7 +1,7 @@ import { doWithDB } from "../db" import { queryPlatformView } from "../db/views" import { StaticDatabases, ViewName } from "../db/constants" -import { baseGlobalDBName } from "./utils" +import { getGlobalDBName } from "./utils" import { getTenantId, DEFAULT_TENANT_ID, @@ -88,15 +88,6 @@ export const tryAddTenant = async ( }) } -export const getGlobalDBName = (tenantId?: string) => { - // tenant ID can be set externally, for example user API where - // new tenants are being created, this may be the case - if (!tenantId) { - tenantId = getTenantId() - } - return baseGlobalDBName(tenantId) -} - export const doWithGlobalDB = (tenantId: string, cb: any) => { return doWithDB(getGlobalDBName(tenantId), cb) } diff --git a/packages/backend-core/src/tenancy/utils.ts b/packages/backend-core/src/tenancy/utils.ts index 9993e550b3..f99f1e30af 100644 --- a/packages/backend-core/src/tenancy/utils.ts +++ b/packages/backend-core/src/tenancy/utils.ts @@ -1,5 +1,15 @@ import { DEFAULT_TENANT_ID } from "../constants" import { StaticDatabases, SEPARATOR } from "../db/constants" +import { getTenantId } from "../context" + +export const getGlobalDBName = (tenantId?: string) => { + // tenant ID can be set externally, for example user API where + // new tenants are being created, this may be the case + if (!tenantId) { + tenantId = getTenantId() + } + return baseGlobalDBName(tenantId) +} export const baseGlobalDBName = (tenantId: string | undefined | null) => { let dbName