Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PostgresStorageAdapter.js #6989

Merged
merged 3 commits into from
Nov 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 ($<className>, $<schema>, 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)
Expand Down