-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(postgres): Add upsertIndex
and upsertKeys
options to BulkCreateOptions
#11611
Conversation
13287e0
to
ce8261b
Compare
Codecov Report
@@ Coverage Diff @@
## master #11611 +/- ##
==========================================
+ Coverage 95.92% 96.40% +0.47%
==========================================
Files 92 95 +3
Lines 8912 9128 +216
==========================================
+ Hits 8549 8800 +251
+ Misses 363 328 -35
Continue to review full report at Codecov.
|
Note: if anyone wants to use this while we go through the PR process, I have a EDIT as of 6/9/2020: I have a new patch for sequelize 5.21.12 to support this in postgres and sqlite: https://gist.github.com/fnimick/313091df3ecc6c5e5f17be1e0950c33f |
Hello! I see you are a first-time contributor, thank you for taking the time to help Sequelize! I hope to see more PRs from you in the future! To help you write tests, can you please first show usage examples of your feature? |
A usage example for
NOTE: the index in question here must be defined on the model as well. A usage example for
A usage example for
|
ce8261b
to
c66afd6
Compare
Hello 😬 thank you very much!! |
If you are having trouble to write tests, I suggest you try playing around with sequelize-sscce, if you can make short pieces of code that verify what you want, converting them to real tests will be almost trivial :) Let me know! |
Hi everyone! 👋 Good job in this PR 🎉. |
Closed because a better approach has been merged in - see #11984 |
@thaddeusmt went to implement my use case for this PR with your updated updateOnDuplicate and realized there's a case that my branch handles, but yours (I don't think) does - a partial unique index. In our case, I have a unique index on two fields only when a third field is null, and I generate an |
482c603
to
23b1d0e
Compare
@papb I've now added postgres specific tests for this. Please let me know if my style of writing them is OK. |
Adds options `upsertKeys` and `upsertIndex`. These options work with sqlite as well as postgres. This allows the use of a unique index for a `bulkCreate` with `updateOnDuplicate` set. The unique index may be a partial index. Closes sequelize#11534, sequelize#11569
23b1d0e
to
42f64bf
Compare
I've now also added sqlite tests, since this feature is supported by sqlite as well, and have improved the documentation on the new options. |
@papb is there anything I can do to move this forward? Thanks! |
Would love to help out to get this done. It's critical for bulkCreate usage on Postgres. |
This PR is urgent to get bulk upsert work correctly on postgres |
Agreed this is urgently needed. Happy to help resolving the conflicts so this can move forward. |
Unfortunately this PR was not reviewed before the rewrite in Typescript was started, so not only are there many conflicts, some of the files I have changed no longer exist. I asked in #12429 about the best strategy, but got no clear answer. I would recommend doing a raw sql query for now - or using sequelize 5.21.1 with my patch, if you absolutely must have the ORM interface which matches this PR. There's no guarantee that this interface will be merged in though, so I would recommend raw queries instead. @CharlesEgan https://gist.github.com/fnimick/313091df3ecc6c5e5f17be1e0950c33f |
This comment has been minimized.
This comment has been minimized.
Hey there :) First of all: Thanks a bunch for your contribution to Sequelize! Much appreciated! A couple of months ago, we have switched from master to main branch as our primary development branch and hence this PR is now outdated :( If you still think this change is making sense, please consider recreating the PR against ✌️ |
Closing this since it is still against |
This allows the use of a unique index for a
bulkCreate
withupdateOnDuplicate
set, in postgres. The unique index may bea partial index.
Pull Request check-list
Please make sure to review and check all of these items:
npm run test
ornpm run test-DIALECT
pass with this change (including linting)?Description of change
This change adds the ability to specify
upsertIndex
orupsertKeys
inBulkCreateOptions
, so that aON CONFLICT
clause can be generated using columns other than the table's primary key.Note: I was not able to get the tests running on my machine, and would appreciate help writing a new test for this functionality.
Closes #11534, #11569