Skip to content

feat(postgres): native updateOnConflict for upsert - #11246

Closed
bmeriaux wants to merge 1 commit into
sequelize:masterfrom
bmeriaux:pgUpsertOnClonflict
Closed

bmeriaux wants to merge 1 commit into
sequelize:masterfrom
bmeriaux:pgUpsertOnClonflict

Conversation

@bmeriaux

@bmeriaux bmeriaux commented Jul 29, 2019 •

Copy link
Copy Markdown
Contributor

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you update the typescript typings accordingly (if applicable)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

replace the function to catch exception on existing element for upsert method with Postgres by the native method ON CONFLICT () UPDATE SET, it is supported by postgres >= 9.5, is this blocking ?

Closes #4132

@bmeriaux
bmeriaux force-pushed the pgUpsertOnClonflict branch from e5179ff to 6ab2ca0 Compare July 30, 2019 00:12
@codecov

codecov Bot commented Jul 30, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #11246 into master will decrease coverage by 8.31%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #11246      +/-   ##
==========================================
- Coverage   96.32%      88%   -8.32%     
==========================================
  Files          94       91       -3     
  Lines        9160     8705     -455     
==========================================
- Hits         8823     7661    -1162     
- Misses        337     1044     +707
Impacted Files Coverage Δ
lib/dialects/abstract/index.js 100% <ø> (ø) ⬆️
lib/dialects/postgres/query-generator.js 1.86% <0%> (-92.67%) ⬇️
lib/dialects/mysql/query-generator.js 97.88% <100%> (ø) ⬆️
lib/model.js 96.24% <33.33%> (-0.23%) ⬇️
lib/dialects/abstract/query-generator.js 94.4% <70%> (-3.21%) ⬇️
lib/dialects/postgres/range.js 7.69% <0%> (-92.31%) ⬇️
lib/dialects/postgres/query-interface.js 11.11% <0%> (-87.38%) ⬇️
lib/errors/database/exclusion-constraint-error.js 18.18% <0%> (-81.82%) ⬇️
lib/dialects/postgres/data-types.js 19.62% <0%> (-76.64%) ⬇️
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 83e263b...2bfb9c4. Read the comment docs.

@bmeriaux
bmeriaux force-pushed the pgUpsertOnClonflict branch from 6ab2ca0 to 9bd5f26 Compare July 30, 2019 00:24
@papb

papb commented Jul 30, 2019

Copy link
Copy Markdown
Member

postgres >= 9.5, is this blocking ?

Without your PR, what is the minimum required postgres version? (I probably should know this, but I don't...)

@papb papb added dialect: postgres For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects). status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action type: refactor DEPRECATED: replace with the "meta" issue type labels Jul 30, 2019
@bmeriaux
bmeriaux force-pushed the pgUpsertOnClonflict branch from 9bd5f26 to b254f4e Compare July 30, 2019 20:57
@bmeriaux

Copy link
Copy Markdown
Contributor Author

if we look at the previous default version, it was 9.4
but a previous PR #11163 on bulkInsert with the same ON CONFLICT syntax already implicit set required version to 9.5

@papb

papb commented Jul 30, 2019

Copy link
Copy Markdown
Member

I see. Thanks! I think it is better for @sushantdhiman to take a look.

@papb papb added status: awaiting approval and removed status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action labels Jul 30, 2019
@bmeriaux
bmeriaux force-pushed the pgUpsertOnClonflict branch 5 times, most recently from 772dbc1 to 20374bb Compare July 31, 2019 07:24
@sushantdhiman

Copy link
Copy Markdown
Contributor

Tests are failing

@sushantdhiman sushantdhiman added status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action and removed status: awaiting maintainer labels Aug 4, 2019
@up73k

up73k commented Aug 13, 2019

Copy link
Copy Markdown

@bmeriaux, will you fix tests in nearest future?

@papb

papb commented Aug 13, 2019

Copy link
Copy Markdown
Member

Also, there are conflicts with the master branch, @bmeriaux please rebase your branch.

@bmeriaux

bmeriaux commented Aug 13, 2019 via email •

Copy link
Copy Markdown
Contributor Author

@papb

papb commented Aug 13, 2019

Copy link
Copy Markdown
Member

I will try this week. But I find out that with this native upsert, we lose the information if it is an insert or an update, And it may not work on case with 2 distinct unique constraints. So i do not know if we must detect in which case we are to keep existing temp function for some edge case, and use native upsert for others ? What did you think ?

Can you show a SSCCE/MVCE/reprex for the situation that is covered by Sequelize's workaround that is not covered by the native implementation?

@bmeriaux
bmeriaux force-pushed the pgUpsertOnClonflict branch from 20374bb to 42e07a5 Compare August 16, 2019 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dialect: postgres For issues and PRs. Things that involve PostgreSQL (and do not involve all dialects). status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action type: refactor DEPRECATED: replace with the "meta" issue type

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Postgres UPSERT native support

4 participants