Skip to content
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

fix(mongo,postgres): create/upsert autoInc field with primary set #77

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Hieuzest
Copy link
Contributor

Consider the following snippets with autoInc enabled:

await database.create('foo', { id: 1 })
await database.create('foo', { num: 1 })

Currently in mongo driver, create({ id: 1}) will not update autoInc field, thus the second create({ num: 1 }) will get the same id=1, causing duplicate primary error.

PostgreSQL's serial type acts exactly our mongo's way. It only update itself when triggering default. The PR gives a workaround but i have no idea whether there exists better solution.

Unit tests are missing in the PR because there are not proper file to write them. (current update.ts will not run into problem cuz the autoInc is already high enough in that case) We should write them in model.ts later the other PR is merged.

Copy link

codecov bot commented Mar 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.34%. Comparing base (1b88ce9) to head (78e002f).

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #77   +/-   ##
=======================================
  Coverage   98.34%   98.34%           
=======================================
  Files          36       36           
  Lines        7964     7988   +24     
  Branches     1997     2037   +40     
=======================================
+ Hits         7832     7856   +24     
  Misses        132      132           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hieuzest Hieuzest changed the title fix: create/upsert autoInc field with primary set fix(mongo,postgres): create/upsert autoInc field with primary set Mar 13, 2024
@Hieuzest Hieuzest marked this pull request as draft April 1, 2024 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant