Add API for checking uniqueness constraints for updates#1140
Merged
parsonsmatt merged 5 commits intoyesodweb:masterfrom Oct 29, 2020
Merged
Add API for checking uniqueness constraints for updates#1140parsonsmatt merged 5 commits intoyesodweb:masterfrom
parsonsmatt merged 5 commits intoyesodweb:masterfrom
Conversation
Entities which are already in the DB will conflict with themselves when using `checkUnique`, unless the value of each unique key is changed. This adds an alternative `checkUniqueUpdateable` which ignores conflicts from an entity with itself, so that uniqueness constraints can be checked without an update.
parsonsmatt
approved these changes
Oct 26, 2020
Collaborator
parsonsmatt
left a comment
There was a problem hiding this comment.
Would you mind writing a quick test for this?
| Nothing -> checkUniqueKeysUpdateable key xs | ||
| Just (Entity k _) | ||
| | key == k -> checkUniqueKeysUpdateable key xs | ||
| Just _ -> return (Just x) |
Collaborator
There was a problem hiding this comment.
This is fantastic, thanks!
| -- | ||
| -- While this would be 'Just' because SPJ already exists: | ||
| -- | ||
| -- > mSpjConst <- checkUnique $ User "SPJ" 60 |
Collaborator
There was a problem hiding this comment.
Awesome docs, thanks 😄
Contributor
Author
There was a problem hiding this comment.
I can't take the credit - these are largely copied from checkUnique, plus a paragraph on the difference in behaviour.
Contributor
Author
|
Alright, I've added a test for the basic behaviour - an entity not clashing with itself, but still clashing with other entities. |
Collaborator
|
Looks great, thanks so much! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Entities which are already in the DB will conflict with themselves when using
checkUnique, unless the value of each unique key is changed. This adds an alternativecheckUniqueUpdateablewhich ignores conflicts from an entity with itself, so that uniqueness constraints can be checked without an update.Before submitting your PR, check that you've:
@sincedeclarations to the HaddockAfter submitting your PR:
(unreleased)on the Changelog