mirror of
https://github.com/directus/directus.git
synced 2026-01-23 07:47:58 -05: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) {
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
#
|
||||
# Ports:
|
||||
# Postgres: 5100
|
||||
# MySQL: 5101
|
||||
# MySQL (8): 5101
|
||||
# MariaDB: 5102
|
||||
# MS SQL: 5103
|
||||
# Oracle: 5104
|
||||
# Redis: 5105
|
||||
# Minio (S3): 5106
|
||||
# Azure 5107
|
||||
# MySQL (5.7): 5108
|
||||
#
|
||||
# Credentials:
|
||||
# Postgres:
|
||||
@@ -107,3 +108,11 @@ services:
|
||||
image: mcr.microsoft.com/azure-storage/azurite
|
||||
ports:
|
||||
- 5107:10000
|
||||
|
||||
mysql5:
|
||||
image: mysql:5
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: secret
|
||||
MYSQL_DATABASE: directus
|
||||
ports:
|
||||
- 5108:3306
|
||||
|
||||
Reference in New Issue
Block a user