Skip to content

fixing method setIndexesWithSchemaFormat #4454

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

Merged
merged 1 commit into from
Dec 24, 2017
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
26 changes: 10 additions & 16 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ export class PostgresStorageAdapter {

setIndexesWithSchemaFormat(className, submittedIndexes, existingIndexes = {}, fields, conn) {
conn = conn || this._client;
const self = this;
if (submittedIndexes === undefined) {
return Promise.resolve();
}
Expand Down Expand Up @@ -645,22 +646,15 @@ export class PostgresStorageAdapter {
});
}
});
let insertPromise = Promise.resolve();
if (insertedIndexes.length > 0) {
insertPromise = this.createIndexes(className, insertedIndexes, conn);
}
let deletePromise = Promise.resolve();
if (deletedIndexes.length > 0) {
deletePromise = this.dropIndexes(className, deletedIndexes, conn);
}
return conn.task(t => {
const values = [className, 'schema', 'indexes', JSON.stringify(existingIndexes)];
return t.batch([
deletePromise,
insertPromise,
this._ensureSchemaCollectionExists(t),
t.none('UPDATE "_SCHEMA" SET $2:name = json_object_set_key($2:name, $3::text, $4::jsonb) WHERE "className"=$1', values)
]);
return conn.tx('set-indexes-with-schema-format', function * (t) {
if (insertedIndexes.length > 0) {
yield self.createIndexes(className, insertedIndexes, t);
}
if (deletedIndexes.length > 0) {
yield self.dropIndexes(className, deletedIndexes, t);
}
yield self._ensureSchemaCollectionExists(t);
yield t.none('UPDATE "_SCHEMA" SET $2:name = json_object_set_key($2:name, $3::text, $4::jsonb) WHERE "className"=$1', [className, 'schema', 'indexes', JSON.stringify(existingIndexes)]);
});
}

Expand Down