Small update to properly support environments with environment variables, making sure that datasources correctly select based on app ID.
This commit is contained in:
parent
d27674de5c
commit
87cf52192d
|
@ -1,13 +1,18 @@
|
|||
import { environmentVariables } from "@budibase/pro"
|
||||
import { context } from "@budibase/backend-core"
|
||||
import { processObject } from "@budibase/string-templates"
|
||||
import { Datasource } from "@budibase/types"
|
||||
import { context, db as dbCore } from "@budibase/backend-core"
|
||||
import { processObjectSync } from "@budibase/string-templates"
|
||||
import { AppEnvironment, Datasource } from "@budibase/types"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
|
||||
export async function enrichDatasourceWithValues(datasource: Datasource) {
|
||||
const appId = context.getAppId()
|
||||
const appEnv = dbCore.isDevAppID(appId)
|
||||
? AppEnvironment.DEVELOPMENT
|
||||
: AppEnvironment.PRODUCTION
|
||||
const cloned = cloneDeep(datasource)
|
||||
const envVars = await environmentVariables.fetchValues()
|
||||
return (await processObject(cloned, envVars)) as Datasource
|
||||
const envVars = await environmentVariables.fetchValues(appEnv)
|
||||
const processed = processObjectSync(cloned, { env: envVars })
|
||||
return processed as Datasource
|
||||
}
|
||||
|
||||
export async function get(
|
||||
|
|
|
@ -10,10 +10,7 @@ import sdk from "../sdk"
|
|||
import { cloneDeep } from "lodash/fp"
|
||||
|
||||
import { isSQL } from "../integrations/utils"
|
||||
import {
|
||||
enrichQueryFields,
|
||||
interpolateSQL,
|
||||
} from "../integrations/queries/sql"
|
||||
import { enrichQueryFields, interpolateSQL } from "../integrations/queries/sql"
|
||||
|
||||
class QueryRunner {
|
||||
datasource: any
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
export enum AppEnvironment {
|
||||
PRODUCTION = "production",
|
||||
DEVELOPMENT = "development",
|
||||
}
|
|
@ -11,3 +11,4 @@ export * from "./locks"
|
|||
export * from "./db"
|
||||
export * from "./middleware"
|
||||
export * from "./featureFlag"
|
||||
export * from "./environmentVariables"
|
||||
|
|
Loading…
Reference in New Issue