feat(csv-to-pg): add conflictDoNothing option for ON CONFLICT DO NOTHING #582
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.
feat(csv-to-pg): add conflictDoNothing option for ON CONFLICT DO NOTHING
Summary
Adds a new
conflictDoNothingoption to the csv-to-pg package that generatesON CONFLICT DO NOTHINGwithout specifying conflict columns. This is needed when the unique constraint uses a functional index with complex expressions that cannot be specified as simple column names.The immediate use case is the
metaschema_public.fieldtable, which has a unique constraint (databases_field_uniq_names_idx) that normalizes UUID field names by stripping suffixes like_id,_uuid, etc. This causes collisions when tables have bothfoo(text) andfoo_id(uuid) columns - they normalize to the same hash value and violate the unique constraint during deployment.Changes:
packages/csv-to-pg/src/utils.ts: AddconflictDoNothingparameter tomakeConflictClause,InsertOne, andInsertManypackages/csv-to-pg/src/parser.ts: AddconflictDoNothingto Parser configpgpm/core/src/export/export-meta.ts: EnableconflictDoNothing: truefor thefieldtable configReview & Testing Checklist for Human
ON CONFLICT DO NOTHINGmeans duplicate field records will be silently skipped. Confirm this is the desired behavior and no important data will be lost.generate:constructivein constructive-db and deploy to a test database to verify the fix resolves the unique constraint violation error.Recommended test plan:
Notes
This PR is part of fixing the deployment issue reported in constructive-db where
generate:constructivewas exporting duplicate field entries that violated thedatabases_field_uniq_names_idxconstraint.Link to Devin run: https://app.devin.ai/sessions/7ea5e5e99b73424db6856e5d07482b64
Requested by: Dan Lynch (@pyramation)