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

feat/promotions create auto increment function for generating auto-increment Ids #6645

Merged
merged 10 commits into from
Nov 14, 2022

Conversation

zenweasel
Copy link
Collaborator

@zenweasel zenweasel commented Nov 10, 2022

Resolves reactioncommerce/kinetic#107
Impact: minor
Type: feature

Issue

Unlike most SQL databases Mongo does not have a built in function for creating auto-incrementing IDs

Solution

Using findOneAndUpdate and $inc is a fully atomic operation that is not subject to race-conditions and thus works as an equivalent. Please read that again for commenting, nerds.

Breaking changes

None

Signed-off-by: Brent Hoover <brent@thebuddhalodge.com>
@changeset-bot
Copy link

changeset-bot bot commented Nov 10, 2022

⚠️ No Changeset found

Latest commit: ef527e5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@aldeed aldeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple general comments:

  • A couple Jest tests might be nice to prove it works
  • Readme could show a usage example
  • There is not much code here. Should this be built into core and available always on context similar to getAbsoluteUrl?

export const Sequence = new SimpleSchema({
shopId: String,
entity: String,
value: SimpleSchema.Integer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding min: 0 validation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aldeed Could not think of what to write tests for since it relies to heavily on the db which would need to mocked

Signed-off-by: Brent Hoover <brent@thebuddhalodge.com>
Signed-off-by: Brent Hoover <brent@thebuddhalodge.com>
Signed-off-by: Brent Hoover <brent@thebuddhalodge.com>
…ment-id

Signed-off-by: Brent Hoover <brent@thebuddhalodge.com>
Signed-off-by: Brent Hoover <brent@thebuddhalodge.com>
Signed-off-by: Brent Hoover <brent@thebuddhalodge.com>
Signed-off-by: Brent Hoover <brent@thebuddhalodge.com>
Signed-off-by: Brent Hoover <brent@thebuddhalodge.com>
Signed-off-by: Brent Hoover <brent@thebuddhalodge.com>
@zenweasel zenweasel merged commit 11c1754 into feat/promotions Nov 14, 2022
@zenweasel zenweasel deleted the feat/promotions-create-auto-increment-id branch November 14, 2022 10:12
vanpho93 pushed a commit that referenced this pull request Apr 24, 2023
…-auto-increment-id

feat/promotions create auto increment function for generating auto-increment Ids
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

3 participants