feat: add multi-database support via df.start() database parameter - #41
Merged
Merged
Conversation
Allow durable functions to target any database on the cluster by adding an optional 'database' parameter to df.start(). A single function invocation targets exactly one database; cross-database workflows can use dblink/postgres_fdw or separate durable functions. Changes: - Add 'database TEXT' column to df.nodes and df.instances - Add 'database' parameter to df.start() with pg_database validation - Thread database through FunctionNode, load_function_graph, execute_sql activity, orchestration, and connect_as_user() - Add E2E test (34_multi_database.sql) covering cross-database execution, invalid database rejection, and backward compatibility
Contributor
There was a problem hiding this comment.
Pull request overview
Adds multi-database targeting to pg_durable by allowing df.start() to specify a target database per durable-function invocation, while keeping pg_durable metadata and orchestration in the extension’s home database.
Changes:
- Extend
df.start()with an optionaldatabaseparameter and validate it againstpg_database. - Plumb the database value through nodes/instances metadata, graph loading, orchestration input, and SQL execution connections.
- Add an E2E test covering cross-database execution, invalid database rejection, and backward compatibility.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/dsl.rs |
Adds database parameter to df.start(), validates existence, persists it to df.nodes/df.instances. |
src/lib.rs |
Adds database column to df.nodes and df.instances DDL; updates unit tests for new start() signature. |
src/types.rs |
Adds database to FunctionNode; extends connect_as_user() to accept an optional database. |
src/activities/load_function_graph.rs |
Loads database from df.nodes into FunctionNode. |
src/orchestrations/execute_function_graph.rs |
Passes node.database into execute_sql activity input JSON. |
src/activities/execute_sql.rs |
Includes database in activity input and uses it to connect to the right DB; improves trace logging. |
tests/e2e/sql/34_multi_database.sql |
New E2E test for cross-database execution + invalid DB rejection + regression behavior. |
scripts/test-e2e-local.sh |
Ensures test 34 runs under superuser (creates/drops a database). |
docs/multi-database.md |
Design spec documenting API, behavior, schema, and testing strategy. |
- Handle SPI errors explicitly in database existence check (dsl.rs) instead of swallowing via .ok().flatten() - Move SET/RESET SESSION AUTHORIZATION outside DO block in test 34 where PL/pgSQL does not allow these statements
- Include database name in connect_as_user error message for easier debugging of multi-database connection failures - Add test 4: multi-node sequence graph targeting another database - Add test 5: deferred connection failure when database is dropped after df.start() (uses df.loop to verify clean failure)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Allow durable functions to target any database on the cluster by adding an optional
databaseparameter todf.start(). A single function invocation targets exactly one database; cross-database workflows can usedblink/postgres_fdwor separate durable functions.Design spec: docs/multi-database.md
API
Invalid database names are rejected immediately at
df.start()time.Changes
src/lib.rsdatabase TEXTcolumn todf.nodesanddf.instancesDDLsrc/dsl.rsdatabaseparam todf.start()withpg_databasevalidationsrc/types.rsdatabasetoFunctionNode; adddatabaseparam toconnect_as_user()src/activities/execute_sql.rsdatabasetoExecuteSqlInput, pass toconnect_as_user()src/activities/load_function_graph.rsdatabasein node SELECTsrc/orchestrations/execute_function_graph.rsnode.databasein SQL activity inputtests/e2e/sql/34_multi_database.sqlscripts/test-e2e-local.shTesting