2022-09-13 23:22:03 +12:00
|
|
|
import { DEFAULT_TENANT_ID } from "../constants"
|
2022-09-20 21:20:36 +12:00
|
|
|
import { StaticDatabases, SEPARATOR } from "./constants"
|
2022-09-14 04:29:31 +12:00
|
|
|
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)
|
|
|
|
}
|
2022-04-20 06:42:52 +12:00
|
|
|
|
2022-09-13 23:22:03 +12:00
|
|
|
export const baseGlobalDBName = (tenantId: string | undefined | null) => {
|
2022-04-20 06:42:52 +12:00
|
|
|
let dbName
|
|
|
|
if (!tenantId || tenantId === DEFAULT_TENANT_ID) {
|
|
|
|
dbName = StaticDatabases.GLOBAL.name
|
|
|
|
} else {
|
|
|
|
dbName = `${tenantId}${SEPARATOR}${StaticDatabases.GLOBAL.name}`
|
|
|
|
}
|
|
|
|
return dbName
|
|
|
|
}
|