-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Added unique indexes to rawAttributes #7196
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
Added unique indexes to rawAttributes #7196
Conversation
Codecov Report
Continue to review full report at Codecov.
|
lib/model.js
Outdated
index = this._conformIndex(index); | ||
//Add unique indexes to rawAttributes | ||
if (index.unique && index.fields) { | ||
index.fields.forEach(field => { |
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.
What will happen in case of unique index on two fields (composite unique index), will it mark both fields as unique
? I would like to see a test which works in case of composite unique index
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.
@sushantdhiman Composite index also works. I have added an unit test for it but I'll add an integration test aswell.
lib/model.js
Outdated
index = this._conformIndex(index); | ||
//Add unique indexes to rawAttributes | ||
if (index.unique && index.fields) { | ||
index.fields.forEach(field => { |
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.
use for of
lib/model.js
Outdated
//Add unique indexes to rawAttributes | ||
if (index.unique && index.fields) { | ||
index.fields.forEach(field => { | ||
const fieldName = (typeof field === 'string') ? field : (field.name || field.attribute); |
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.
unneeded parens and space
30c9b1f
to
d90bc38
Compare
d90bc38
to
be32db4
Compare
@sushantdhiman Looks like the deadlocks still occur. Was this not fixed by #7131? |
* Added unique indexes to rawAttributes * Add changelog entry * Added integration test to cover composite unique keys, review fixes * Fixes failing tests
Pull Request check-list
npm run test
ornpm run test-DIALECT
pass with this change (including linting)?Future
in the changelog?Description of change
indexes
defined via the following snippet are not added toModel.rawAttributes
.Model.upsert
query usesrawAttributes
to find primary/unique indexes and hence the upsert query would fail in case of the above model definition.Fixes #6842 (comment)