mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Fixed unique constraint violation error extraction for MySQL 5.7 (#6059)
* Add MySQL 5.7 docker debug instance * Fix unique error constraint extraction in MySQL 5.7 Fixes #5719
This commit is contained in:
@@ -43,28 +43,51 @@ function uniqueViolation(error: MySQLError) {
|
||||
|
||||
if (!matches) return error;
|
||||
|
||||
const collection = matches[1].slice(1, -1).split('.')[0];
|
||||
|
||||
let field = null;
|
||||
|
||||
/**
|
||||
* MySQL's error doesn't return the field name in the error. In case the field is created through
|
||||
* Directus (/ Knex), the key name will be `<collection>_<field>_unique` in which case we can pull
|
||||
* the field name from the key name
|
||||
*/
|
||||
const indexName = matches[1].slice(1, -1).split('.')[1];
|
||||
|
||||
if (indexName?.startsWith(`${collection}_`) && indexName.endsWith('_unique')) {
|
||||
field = indexName.slice(collection.length + 1, -7);
|
||||
/** MySQL 8+ style error message */
|
||||
if (matches[1].includes('.')) {
|
||||
const collection = matches[1].slice(1, -1).split('.')[0];
|
||||
|
||||
let field = null;
|
||||
|
||||
const indexName = matches[1].slice(1, -1).split('.')[1];
|
||||
|
||||
if (indexName?.startsWith(`${collection}_`) && indexName.endsWith('_unique')) {
|
||||
field = indexName.slice(collection.length + 1, -7);
|
||||
}
|
||||
|
||||
const invalid = matches[0].slice(1, -1);
|
||||
|
||||
return new RecordNotUniqueException(field, {
|
||||
collection,
|
||||
field,
|
||||
invalid,
|
||||
});
|
||||
} else {
|
||||
/** MySQL 5.7 style error message */
|
||||
const indexName = matches[1].slice(1, -1);
|
||||
|
||||
const collection = indexName.split('_')[0];
|
||||
|
||||
let field = null;
|
||||
|
||||
if (indexName?.startsWith(`${collection}_`) && indexName.endsWith('_unique')) {
|
||||
field = indexName.slice(collection.length + 1, -7);
|
||||
}
|
||||
|
||||
const invalid = matches[0].slice(1, -1);
|
||||
|
||||
return new RecordNotUniqueException(field, {
|
||||
collection,
|
||||
field,
|
||||
invalid,
|
||||
});
|
||||
}
|
||||
|
||||
const invalid = matches[0].slice(1, -1);
|
||||
|
||||
return new RecordNotUniqueException(field, {
|
||||
collection,
|
||||
field,
|
||||
invalid,
|
||||
});
|
||||
}
|
||||
|
||||
function numericValueOutOfRange(error: MySQLError) {
|
||||
|
||||
Reference in New Issue
Block a user