Wrapped data generator data creation in transaction function

ref PROD-233

Errors were not handled properly because of a missing rollback and try/catch.

Using a function is easier generally.

Also added ignored contraint checks to increase performance a tiny bit.
They ended up not mattering much, so we can consider to remove them again.
This commit is contained in:
Simon Backx 2023-12-12 17:36:00 +01:00 committed by Simon Backx
parent eebf0e2eaf
commit 52566dc1e0

View File

@ -149,7 +149,10 @@ class DataGenerator {
}
async importData() {
const transaction = await this.knex.transaction();
await this.knex.transaction(async (transaction) => {
// Performance improvements
await this.knex.raw('SET FOREIGN_KEY_CHECKS=0;').transacting(transaction);
await this.knex.raw('SET unique_checks=0;').transacting(transaction);
// Add default tables if none are specified
if (this.tableList.length === 0) {
@ -243,7 +246,10 @@ class DataGenerator {
await tableImporter.finalise();
}
await transaction.commit();
// Performance improvements
await this.knex.raw('SET FOREIGN_KEY_CHECKS=1;').transacting(transaction);
await this.knex.raw('SET unique_checks=1;').transacting(transaction);
}, {isolationLevel: 'read committed'});
}
}