Skip to content
Closed
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
39 changes: 24 additions & 15 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,24 +662,33 @@ export class PostgresStorageAdapter {

createClass(className, schema, conn) {
conn = conn || this._client;
return conn.tx('create-class', t => {
const q1 = this.createTable(className, schema, t);
const q2 = t.none('INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($<className>, $<schema>, true)', { className, schema });
const q3 = this.setIndexesWithSchemaFormat(className, schema.indexes, {}, schema.fields, t);
return t.batch([q1, q2, q3]);
})
.then(() => {
return toParseSchema(schema);
})
.catch(err => {
if (err.data[0].result.code === PostgresTransactionAbortedError) {
err = err.data[1].result;
const self = this;

return conn.tx('create-class', function * (t) {
let error;
try {
yield self.createTable(className, schema, t);
} catch(e) {
if (e.code === PostgresTransactionAbortedError) {
error = e;
}
if (err.code === PostgresUniqueIndexViolationError && err.detail.includes(className)) {
}
try {
yield t.none('INSERT INTO "_SCHEMA" ("className", "schema", "isParseClass") VALUES ($<className>, $<schema>, true)', { className, schema });
} catch(e) {
error = e;
}
if (error) {
if (error.code === PostgresUniqueIndexViolationError && error.detail.includes(className)) {
throw new Parse.Error(Parse.Error.DUPLICATE_VALUE, `Class ${className} already exists.`)
}
throw err;
})
throw error;
}
yield self.setIndexesWithSchemaFormat(className, schema.indexes, {}, schema.fields, t);
})
.then(() => {
return toParseSchema(schema);
});
}

// Just create a table, do not insert in schema
Expand Down