feat: add graphile-bulk-mutations plugin#1140
Open
pyramation wants to merge 2 commits into
Open
Conversation
Adds a PostGraphile v5 plugin for bulk insert, upsert, update, and delete mutations with ON CONFLICT handling. Features: - bulkCreateX: INSERT ... VALUES with optional ON CONFLICT DO NOTHING - bulkUpsertX: INSERT ... ON CONFLICT DO UPDATE SET (per-column control) - bulkUpdateX: UPDATE ... SET ... WHERE (connection-filter conditions) - bulkDeleteX: DELETE ... WHERE (connection-filter conditions) Design decisions: - Opt-in per table via smart tags (@behavior +bulkInsert etc.) - Three-layer gating: database enable_bulk + api enable_bulk + smart tags - Configurable naming: bulk (default), pluralized, many - Auto-batch at PostgreSQL 32K parameter limit - Per-table constraint enums and column enums for ON CONFLICT - Safety guards: bulkMaxRows (1000), bulkRequireWhere (true) Closes constructive-io/constructive-planning#844
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
- Fix plan functions: use getRaw('input') for proper Grafast step resolution
- Fix constraint targeting: use column-based ON CONFLICT (col1, col2) instead of
constraint names, since PgResourceUnique doesn't store PG constraint names
- Fix WHERE clause builder: support both simple equality (Condition type) and
operator-based (Filter type) conditions
- Fix sql-builder: use conflictColumns instead of constraintName
- Add integration tests: 4 schema generation + 3 insert + 1 upsert + 1 update + 1 delete
- Add test seed SQL with smart tags for bulk behavior opt-in
- Align README with other graphile packages (logo, badges, examples)
- Remove debug logging
- Column-level SELECT grant safety (RETURNING <pk> + follow-up SELECT)
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
Adds
graphile-bulk-mutations— a PostGraphile v5 plugin for bulk insert, upsert, update, and delete mutations with ON CONFLICT handling and column-level grant safety.Features:
ON CONFLICT DO NOTHINGON CONFLICT DO UPDATE SET(selective column updates viaupdateColumns)ConditionandFiltertypes)RETURNING <pk_columns>+ follow-up SELECT instead ofRETURNING *@behavior +bulkInsert +bulkUpsert +bulkUpdate +bulkDelete)ON CONFLICT (col1, col2))bulkMaxRows,bulkRequireWhere,bulkNamingArchitecture: 6 plugins (
BulkInflectionPlugin,BulkTypesPlugin,BulkInsertPlugin,BulkUpsertPlugin,BulkUpdatePlugin,BulkDeletePlugin) usingsideEffectWithPgClientfor raw SQL execution.Tests: 10 integration tests via
graphile-test— 4 schema generation, 3 insert, 1 upsert, 1 update, 1 delete.Related: Planning issue #844
Review & Testing Checklist for Human
RETURNING <pk>+ follow-up SELECT pattern should handle this, but hasn't been tested with restricted roles)graphile-connection-filterpreset to verify operator-based WHERE conditions work (current tests only cover simple equality viaConditiontype)updateColumnsoption works correctly (selectively updating specific columns on conflict)Recommended test plan
@behavior +bulkInsert +bulkUpsertto a test table with column-level SELECT grantsonConflict: { constraint: <ENUM>, action: IGNORE }where: { name: { startsWith: "A" } }on bulk update/deleteNotes
ON CONFLICT ("col1", "col2")) instead of constraint names becausePgResourceUniquedoesn't store the actual PostgreSQL constraint nameConditiontype) and operator-based filtering (Filtertype fromgraphile-connection-filter)Link to Devin session: https://app.devin.ai/sessions/b5701e74c8b44bbf89db370f3323acf2
Requested by: @pyramation