sequelize/sequelize — pull request #2568 by jamonkko (2014-11-12 21:34:48+00:00)
Title: Prefer index name when mapping unique constraint errors

When using migrations instead of sync to create indexes or when unique index name has fields with underscores (was problem at least with postgres implementation) then it was not possible to set custom error message, because mapping the error thrown from database always failed.

Fixed by using indexName always for mapping the error if possible. Also if the name matches then the array of fields passed to the error will be taken from the model definition, not from the parsed index name, because if fields have underscores in them, then the parsing (at least with postgres) will return wrong fields. E.g. name_id field would be parsed to ['name', 'id']

Added also test. Without this fix the test will fail when using postgres dialect.