-
Notifications
You must be signed in to change notification settings - Fork 293
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
Add API for checking uniqueness constraints for updates #1140
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic, thanks!
-- | ||
-- While this would be 'Just' because SPJ already exists: | ||
-- | ||
-- > mSpjConst <- checkUnique $ User "SPJ" 60 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome docs, thanks 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't take the credit - these are largely copied from checkUnique
, plus a paragraph on the difference in behaviour.
Alright, I've added a test for the basic behaviour - an entity not clashing with itself, but still clashing with other entities. |
Looks great, thanks so much! |
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 alternativecheckUniqueUpdateable
which 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:
@since
declarations to the HaddockAfter submitting your PR:
(unreleased)
on the Changelog