@@ -15,6 +15,7 @@ const PostgresRelationDoesNotExistError = '42P01';
15
15
const PostgresDuplicateRelationError = '42P07' ;
16
16
const PostgresDuplicateColumnError = '42701' ;
17
17
const PostgresMissingColumnError = '42703' ;
18
+ const PostgresDuplicateObjectError = '42710' ;
18
19
const PostgresUniqueIndexViolationError = '23505' ;
19
20
const logger = require ( '../../../logger' ) ;
20
21
@@ -905,7 +906,15 @@ export class PostgresStorageAdapter implements StorageAdapter {
905
906
'CREATE TABLE IF NOT EXISTS "_SCHEMA" ( "className" varChar(120), "schema" jsonb, "isParseClass" bool, PRIMARY KEY ("className") )'
906
907
)
907
908
. catch ( error => {
908
- throw error ;
909
+ if (
910
+ error . code === PostgresDuplicateRelationError ||
911
+ error . code === PostgresUniqueIndexViolationError ||
912
+ error . code === PostgresDuplicateObjectError
913
+ ) {
914
+ // Table already exists, must have been created by a different request. Ignore error.
915
+ } else {
916
+ throw error ;
917
+ }
909
918
} ) ;
910
919
}
911
920
@@ -2446,7 +2455,23 @@ export class PostgresStorageAdapter implements StorageAdapter {
2446
2455
}
2447
2456
await conn.none(qs, [indexNameOptions.name, className, ...fieldNames])
2448
2457
.catch(error => {
2449
- throw error;
2458
+ if (
2459
+ error.code === PostgresDuplicateRelationError &&
2460
+ error.message.includes(indexNameOptions.name)
2461
+ ) {
2462
+ // Index already exists. Ignore error.
2463
+ } else if (
2464
+ error.code === PostgresUniqueIndexViolationError &&
2465
+ error.message.includes(indexNameOptions.name)
2466
+ ) {
2467
+ // Cast the error into the proper parse error
2468
+ throw new Parse.Error(
2469
+ Parse.Error.DUPLICATE_VALUE,
2470
+ 'A duplicate value for a field with unique values was provided'
2471
+ );
2472
+ } else {
2473
+ throw error;
2474
+ }
2450
2475
});
2451
2476
}
2452
2477
0 commit comments