From bbae55d518f3541ce2df4b6514357cc441c57bf6 Mon Sep 17 00:00:00 2001 From: Vitaly Tomilov Date: Tue, 3 Nov 2020 16:01:04 +0000 Subject: [PATCH] Update PostgresStorageAdapter.js (#6989) * Update PostgresStorageAdapter.js Improve `createClass` transaction: * `await` makes it a more consistent sequence of queries * `batch` is not needed there * No need for an extra `.then` section * Update PostgresStorageAdapter.js Remove batch-dependent error code check, as it should happen automatically without batch result. * Update PostgresStorageAdapter.js Removing unused variable. --- .../Storage/Postgres/PostgresStorageAdapter.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js index ada6c51a..aa2ddf3f 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -12,7 +12,6 @@ const PostgresDuplicateColumnError = '42701'; const PostgresMissingColumnError = '42703'; const PostgresDuplicateObjectError = '42710'; const PostgresUniqueIndexViolationError = '23505'; -const PostgresTransactionAbortedError = '25P02'; const logger = require('../../../logger'); const debug = function (...args: any) { @@ -986,29 +985,21 @@ export class PostgresStorageAdapter implements StorageAdapter { conn = conn || this._client; return conn .tx('create-class', async t => { - const q1 = this.createTable(className, schema, t); - const q2 = t.none( + await this.createTable(className, schema, t); + await t.none( 'INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($, $, true)', { className, schema } ); - const q3 = this.setIndexesWithSchemaFormat( + await this.setIndexesWithSchemaFormat( className, schema.indexes, {}, schema.fields, t ); - // TODO: The test should not verify the returned value, and then - // the method can be simplified, to avoid returning useless stuff. - return t.batch([q1, q2, q3]); - }) - .then(() => { return toParseSchema(schema); }) .catch(err => { - if (err.data[0].result.code === PostgresTransactionAbortedError) { - err = err.data[1].result; - } if ( err.code === PostgresUniqueIndexViolationError && err.detail.includes(className)