Skip to content

Commit d149d16

Browse files
vitaly-tflovilmart
authored andcommitted
fix(PostgresStorageAdapter): Use transactions when deleting classes (#3869)
* Update PostgresStorageAdapter.js refactoring `deleteClass`. * Update PostgresStorageAdapter.js
1 parent aedaae1 commit d149d16

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,12 @@ export class PostgresStorageAdapter {
564564
// Drops a collection. Resolves with true if it was a Parse Schema (eg. _User, Custom, etc.)
565565
// and resolves with false if it wasn't (eg. a join table). Rejects if deletion was impossible.
566566
deleteClass(className) {
567-
return Promise.resolve().then(() => {
568-
const operations = [[`DROP TABLE IF EXISTS $1:name`, [className]],
569-
[`DELETE FROM "_SCHEMA" WHERE "className"=$1`, [className]]];
570-
return this._client.tx(t=>t.batch(operations.map(statement=>t.none(statement[0], statement[1]))));
571-
}).then(() => {
572-
// resolves with false when _Join table
573-
return className.indexOf('_Join:') != 0;
574-
});
567+
const operations = [
568+
{query: `DROP TABLE IF EXISTS $1:name`, values: [className]},
569+
{query: `DELETE FROM "_SCHEMA" WHERE "className" = $1`, values: [className]}
570+
];
571+
return this._client.tx(t => t.none(this._pgp.helpers.concat(operations)))
572+
.then(() => className.indexOf('_Join:') != 0); // resolves with false when _Join table
575573
}
576574

577575
// Delete all data known to this adapter. Used for testing.

0 commit comments

Comments
 (0)