Skip to content

Commit f23c0a5

Browse files
kulshekharflovilmart
authored andcommitted
Fix the error returned when class already exists (#2955)
* Fix the error returned when class already exists * Wrap the class creation in a transaction
1 parent 4a5ed10 commit f23c0a5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,18 @@ export class PostgresStorageAdapter {
410410
}
411411

412412
createClass(className, schema) {
413-
return this.createTable(className, schema)
414-
.then(() => this._client.none('INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($<className>, $<schema>, true)', { className, schema }))
413+
return this._client.tx(t => {
414+
const q1 = this.createTable(className, schema);
415+
const q2 = this._client.none('INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($<className>, $<schema>, true)', { className, schema });
416+
417+
return t.batch([q1, q2]);
418+
})
415419
.then(() => {
416420
return toParseSchema(schema)
417421
})
418422
.catch((err) => {
419423
if (err.code === PostgresUniqueIndexViolationError && err.detail.includes(className)) {
420-
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${className} already exists.`)
424+
throw new Parse.Error(Parse.Error.DUPLICATE_VALUE, `Class ${className} already exists.`)
421425
}
422426
throw err;
423427
})

0 commit comments

Comments
 (0)