fixing method setIndexesWithSchemaFormat (#4454)
Fixing invalid database code in method `setIndexesWithSchemaFormat`: * It must be a transaction, not a task, as it executes multiple database changes * It should contain the initial queries inside the transaction, providing the context, not outside it; * Replaced the code with the ES6 Generator notation * Removing the use of batch, as the value of the result promise is irrelevant, only success/failure that matters
This commit is contained in:
@@ -613,6 +613,7 @@ export class PostgresStorageAdapter {
|
|||||||
|
|
||||||
setIndexesWithSchemaFormat(className, submittedIndexes, existingIndexes = {}, fields, conn) {
|
setIndexesWithSchemaFormat(className, submittedIndexes, existingIndexes = {}, fields, conn) {
|
||||||
conn = conn || this._client;
|
conn = conn || this._client;
|
||||||
|
const self = this;
|
||||||
if (submittedIndexes === undefined) {
|
if (submittedIndexes === undefined) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
@@ -645,22 +646,15 @@ export class PostgresStorageAdapter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let insertPromise = Promise.resolve();
|
return conn.tx('set-indexes-with-schema-format', function * (t) {
|
||||||
if (insertedIndexes.length > 0) {
|
if (insertedIndexes.length > 0) {
|
||||||
insertPromise = this.createIndexes(className, insertedIndexes, conn);
|
yield self.createIndexes(className, insertedIndexes, t);
|
||||||
}
|
}
|
||||||
let deletePromise = Promise.resolve();
|
if (deletedIndexes.length > 0) {
|
||||||
if (deletedIndexes.length > 0) {
|
yield self.dropIndexes(className, deletedIndexes, t);
|
||||||
deletePromise = this.dropIndexes(className, deletedIndexes, conn);
|
}
|
||||||
}
|
yield self._ensureSchemaCollectionExists(t);
|
||||||
return conn.task(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)]);
|
||||||
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)
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user