Skip to content

Commit 12e8945

Browse files
committed
revert adapter file
1 parent 7c78abb commit 12e8945

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const PostgresRelationDoesNotExistError = '42P01';
1515
const PostgresDuplicateRelationError = '42P07';
1616
const PostgresDuplicateColumnError = '42701';
1717
const PostgresMissingColumnError = '42703';
18+
const PostgresDuplicateObjectError = '42710';
1819
const PostgresUniqueIndexViolationError = '23505';
1920
const logger = require('../../../logger');
2021

@@ -905,7 +906,15 @@ export class PostgresStorageAdapter implements StorageAdapter {
905906
'CREATE TABLE IF NOT EXISTS "_SCHEMA" ( "className" varChar(120), "schema" jsonb, "isParseClass" bool, PRIMARY KEY ("className") )'
906907
)
907908
.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+
}
909918
});
910919
}
911920

@@ -2446,7 +2455,23 @@ export class PostgresStorageAdapter implements StorageAdapter {
24462455
}
24472456
await conn.none(qs, [indexNameOptions.name, className, ...fieldNames])
24482457
.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+
}
24502475
});
24512476
}
24522477

0 commit comments

Comments
 (0)