Configure database variables in dataflow#2685
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds first-class “database variables” to the Flow UI so users can define reusable database configurations (name → database code + schema) in the Variables panel, then reference them from DB reader/writer nodes. It also wires the new databases payload through save/export/import/run and into the job plugin / Prefect parameter transformation so DB nodes can resolve variable names to concrete database codes at execution time.
Changes:
- Extend flow state/DTOs to persist
databases: DatabaseVariable[]alongside existing variables/import libs. - Add a new Databases section in the Variables drawer (with a dedicated
DatabaseVariableForm) and update DB reader/writer drawers to select from configured database variables. - Update job plugin parameter transformation to pass
databasesthrough and resolve DB variable names to concrete DB codes/schemas for db_reader/db_writer nodes.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/ui/apps/flow/src/features/flow/types/state.ts | Adds databases to the root flow state shape. |
| plugins/ui/apps/flow/src/features/flow/types/dataflow.state.ts | Adds databases to exported/saved flow DTOs. |
| plugins/ui/apps/flow/src/features/flow/types/common.ts | Introduces DatabaseVariable type. |
| plugins/ui/apps/flow/src/features/flow/reducers.ts | Adds databases to initial state and a replaceDatabases action. |
| plugins/ui/apps/flow/src/features/flow/containers/Node/NodeTypes/DbWriterNode/DbWriterDrawer.tsx | Switches DB selection to configured database variables and auto-fills schema on selection. |
| plugins/ui/apps/flow/src/features/flow/containers/Node/NodeTypes/DbReaderNode/DbReaderDrawer.tsx | Switches DB selection to configured database variables. |
| plugins/ui/apps/flow/src/features/flow/containers/FlowLayout.tsx | Loads databases into Redux from fetched dataflow revisions. |
| plugins/ui/apps/flow/src/features/flow/containers/Flow/SaveFlow/SaveFlowDialog.tsx | Persists databases when saving flows (including template creation path). |
| plugins/ui/apps/flow/src/features/flow/containers/Flow/RunFlow/RunFlowButton.tsx | Includes databases in test-run request payload. |
| plugins/ui/apps/flow/src/features/flow/containers/Flow/ImportFlow/ImportFlowButton.tsx | Imports databases from JSON and stores in Redux. |
| plugins/ui/apps/flow/src/features/flow/containers/Flow/FlowVariables/FlowVariablesDrawer.tsx | Adds Databases editor UI and applies replaceDatabases on Apply. |
| plugins/ui/apps/flow/src/features/flow/containers/Flow/FlowVariables/FlowVariablesButton.tsx | Updates badge count to include databases + variables. |
| plugins/ui/apps/flow/src/features/flow/containers/Flow/FlowVariables/DatabaseVariableForm/DatabaseVariableForm.tsx | New form component for editing database variables. |
| plugins/ui/apps/flow/src/features/flow/containers/Flow/FlowVariables/DatabaseVariableForm/DatabaseVariableForm.scss | Styles for the new database variable form row. |
| plugins/ui/apps/flow/src/features/flow/containers/Flow/ExportFlow/ExportFlowButton.tsx | Exports databases into the JSON export. |
| plugins/functions/jobplugins/src/utils/DataflowParser.ts | Passes databases through and resolves db node database from variable name → db code (+ schema defaulting for writer). |
| plugins/functions/jobplugins/src/types.ts | Adds DatabaseVariable and includes databases in flow/Prefect parameter types. |
| plugins/flows/data_transformation/dataflow_ui_plugin/nodes.py | Injects database variables into Python node execution context via SimpleNamespace. |
| plugins/flows/data_transformation/dataflow_ui_plugin/flow.py | Accepts databases in flow signature and passes them into node execution (notably Python nodes). |
| case NodeType.CSV | NodeType.DBREADER | NodeType.CONCEPTMAPPING | NodeType.FILE | NodeType.WHITERABBIT: | ||
| result = _node.task(task_run_context) | ||
| case NodeType.PYTHON: | ||
| result = _node.task(input, shared_variables, importlibs, task_run_context) | ||
| result = _node.task(input, shared_variables, importlibs, task_run_context, databases or []) |
| def test(self, _input: dict[str, Result], | ||
| shared_variables: dict[str, str], | ||
| importlibs: list[str], | ||
| task_run_context): | ||
| return self.task(_input, shared_variables, importlibs, task_run_context) |
| onChange={(e: SelectChangeEvent<string>) => | ||
| onFormDataChange({ database: e.target.value }) | ||
| } | ||
| disabled={isLoadingDatabases} | ||
| disabled={databases.length === 0} |
| @@ -154,16 +163,27 @@ export const DbWriterDrawer: FC<DbWriterDrawerProps> = ({ | |||
| <Select | |||
| value={formData.database} | |||
| const handleApply = useCallback(() => { | ||
| dispatch(replaceVariables(localVariables)); | ||
| dispatch(replaceImportLibs(localImportLibs)); | ||
| dispatch(replaceDatabases(localDatabases)); | ||
| dispatch(markStatusAsDraft()); | ||
| handleClose(); | ||
| }, [localVariables, localImportLibs, handleClose]); | ||
| }, [localVariables, localImportLibs, localDatabases, handleClose]); |
| export interface IReactFlow { | ||
| nodes: IReactFlowNode[]; | ||
| edges: IReactFlowEdge[]; | ||
| variables: KeyValue[]; | ||
| importLibs: string[]; | ||
| databases: DatabaseVariable[]; | ||
| } |
|
|
||
| const dbList = await dbCredentialsAPI.getDbList(); | ||
| const exist = dbList.find((db) => db.code === env.FHIR_DATABASE_CODE); | ||
| if (exist && exist.dialect === "trex") { |
There was a problem hiding this comment.
We have a dialect that is trex?
There was a problem hiding this comment.
FHIR db entry is created with dialect trex cause of the way its being connected in DBReader nodes.
Merge Checklist
Please cross check this list if additions / modifications needs to be done on top of your core changes and tick them off. Reviewer can as well glance through and help the developer if something is missed out.
developbranch)