Small update to properly support environments with environment variables, making sure that datasources correctly select based on app ID.

This commit is contained in:
mike12345567 2023-01-12 14:38:12 +00:00
parent d27674de5c
commit 87cf52192d
4 changed files with 16 additions and 9 deletions

View File

@ -1,13 +1,18 @@
import { environmentVariables } from "@budibase/pro" import { environmentVariables } from "@budibase/pro"
import { context } from "@budibase/backend-core" import { context, db as dbCore } from "@budibase/backend-core"
import { processObject } from "@budibase/string-templates" import { processObjectSync } from "@budibase/string-templates"
import { Datasource } from "@budibase/types" import { AppEnvironment, Datasource } from "@budibase/types"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
export async function enrichDatasourceWithValues(datasource: Datasource) { export async function enrichDatasourceWithValues(datasource: Datasource) {
const appId = context.getAppId()
const appEnv = dbCore.isDevAppID(appId)
? AppEnvironment.DEVELOPMENT
: AppEnvironment.PRODUCTION
const cloned = cloneDeep(datasource) const cloned = cloneDeep(datasource)
const envVars = await environmentVariables.fetchValues() const envVars = await environmentVariables.fetchValues(appEnv)
return (await processObject(cloned, envVars)) as Datasource const processed = processObjectSync(cloned, { env: envVars })
return processed as Datasource
} }
export async function get( export async function get(

View File

@ -10,10 +10,7 @@ import sdk from "../sdk"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import { isSQL } from "../integrations/utils" import { isSQL } from "../integrations/utils"
import { import { enrichQueryFields, interpolateSQL } from "../integrations/queries/sql"
enrichQueryFields,
interpolateSQL,
} from "../integrations/queries/sql"
class QueryRunner { class QueryRunner {
datasource: any datasource: any

View File

@ -0,0 +1,4 @@
export enum AppEnvironment {
PRODUCTION = "production",
DEVELOPMENT = "development",
}

View File

@ -11,3 +11,4 @@ export * from "./locks"
export * from "./db" export * from "./db"
export * from "./middleware" export * from "./middleware"
export * from "./featureFlag" export * from "./featureFlag"
export * from "./environmentVariables"