fix(PostgresStorageAdapter): Use transactions when deleting classes (#3869)
* Update PostgresStorageAdapter.js refactoring `deleteClass`. * Update PostgresStorageAdapter.js
This commit is contained in:
committed by
Florent Vilmart
parent
aedaae1f23
commit
d149d16fce
@@ -564,14 +564,12 @@ export class PostgresStorageAdapter {
|
|||||||
// Drops a collection. Resolves with true if it was a Parse Schema (eg. _User, Custom, etc.)
|
// Drops a collection. Resolves with true if it was a Parse Schema (eg. _User, Custom, etc.)
|
||||||
// and resolves with false if it wasn't (eg. a join table). Rejects if deletion was impossible.
|
// and resolves with false if it wasn't (eg. a join table). Rejects if deletion was impossible.
|
||||||
deleteClass(className) {
|
deleteClass(className) {
|
||||||
return Promise.resolve().then(() => {
|
const operations = [
|
||||||
const operations = [[`DROP TABLE IF EXISTS $1:name`, [className]],
|
{query: `DROP TABLE IF EXISTS $1:name`, values: [className]},
|
||||||
[`DELETE FROM "_SCHEMA" WHERE "className"=$1`, [className]]];
|
{query: `DELETE FROM "_SCHEMA" WHERE "className" = $1`, values: [className]}
|
||||||
return this._client.tx(t=>t.batch(operations.map(statement=>t.none(statement[0], statement[1]))));
|
];
|
||||||
}).then(() => {
|
return this._client.tx(t => t.none(this._pgp.helpers.concat(operations)))
|
||||||
// resolves with false when _Join table
|
.then(() => className.indexOf('_Join:') != 0); // resolves with false when _Join table
|
||||||
return className.indexOf('_Join:') != 0;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete all data known to this adapter. Used for testing.
|
// Delete all data known to this adapter. Used for testing.
|
||||||
|
|||||||
Reference in New Issue
Block a user