1
0
Fork 0
mirror of synced 2024-09-29 08:41:16 +13:00
budibase/packages/backend-core/src/db/tenancy.ts

23 lines
701 B
TypeScript
Raw Normal View History

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