Fix the error returned when class already exists (#2955)
* Fix the error returned when class already exists * Wrap the class creation in a transaction
This commit is contained in:
committed by
Florent Vilmart
parent
4a5ed1095c
commit
f23c0a57ee
@@ -410,14 +410,18 @@ export class PostgresStorageAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createClass(className, schema) {
|
createClass(className, schema) {
|
||||||
return this.createTable(className, schema)
|
return this._client.tx(t => {
|
||||||
.then(() => this._client.none('INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($<className>, $<schema>, true)', { className, schema }))
|
const q1 = this.createTable(className, schema);
|
||||||
|
const q2 = this._client.none('INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($<className>, $<schema>, true)', { className, schema });
|
||||||
|
|
||||||
|
return t.batch([q1, q2]);
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return toParseSchema(schema)
|
return toParseSchema(schema)
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (err.code === PostgresUniqueIndexViolationError && err.detail.includes(className)) {
|
if (err.code === PostgresUniqueIndexViolationError && err.detail.includes(className)) {
|
||||||
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${className} already exists.`)
|
throw new Parse.Error(Parse.Error.DUPLICATE_VALUE, `Class ${className} already exists.`)
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user