feat(postgres): support configurable schema#293
Conversation
2e2cfe4 to
7477b5b
Compare
thank you!
thank you x2! Reviewing now. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR adds support for configurable database schemas in the PostgreSQL backend, allowing users to isolate OpenWorkflow data within custom schemas rather than being limited to the hardcoded openworkflow schema. This addresses the need for schema-level isolation in scenarios where namespace-level isolation is insufficient (e.g., control plane vs data plane separation).
Changes:
- Added optional
schemaparameter toBackendPostgres.connect()with default value"openworkflow"to maintain backward compatibility - Implemented schema name validation to prevent SQL injection and ensure PostgreSQL identifier compliance
- Updated all database queries to use dynamic schema references via helper methods
- Added comprehensive tests for schema validation and custom schema behavior
- Updated documentation to describe the new schema configuration option
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/openworkflow/postgres/postgres.ts | Added schema validation, updated migrations and utility functions to use dynamic schema with proper SQL escaping |
| packages/openworkflow/postgres/backend.ts | Added schema option, updated all queries to use schema-aware table references via helper methods |
| packages/openworkflow/postgres/postgres.test.ts | Added tests for invalid schema names and length validation |
| packages/openworkflow/postgres/backend.test.ts | Added tests for schema validation errors and custom schema data storage |
| packages/openworkflow/client.test.ts | Refactored test to avoid accessing private backend properties, improved type safety |
| packages/docs/docs/production.mdx | Updated documentation to describe configurable schema option and usage |
| packages/docs/docs/postgres.mdx | Updated documentation with schema configuration examples and clarifications |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { name: "define-wrap-test" }, | ||
| ({ input }) => ({ doubled: (input as { n: number }).n * 2 }), | ||
| ); | ||
| const workflow = client.defineWorkflow< |
There was a problem hiding this comment.
unrelated, but I'll keep
|
merged, will ship in the next release, most likely today |
Summary
schematoBackendPostgres.connectoptions (defaultopenworkflow)"openworkflow"Notes
schemais omittedCloses #291
Disclosure: the changes were done via Codex CLI but I've reviewed each line of code before getting it to open a PR.
Additional notes
I wasn't sure what you meant exactly re. prepared statement issues, but I went with the assumption that you meant the number of prepared statements keeps growing when running the same query repeatedly.
So I got Codex to test it out on this branch, specifically whether
pg_prepared_statementsgrew after running the same query shape.This was the test code used:
Results:
{ "c0": 1, "c1": 2, "c2": 2, "c3": 3 } same-schema plateau: true cross-schema growth: truepg_prepared_statementsshowed one statement forps_check_a.workflow_runsand one forps_check_b.workflow_runs.So the changes here didn't result in any regressions in that regard.