rollback on all errors

This commit is contained in:
Bassel 2023-01-23 12:38:30 +02:00
parent 7c2dcd4b2d
commit ef02eebcf4
2 changed files with 8 additions and 1 deletions

View File

@ -68,6 +68,12 @@ class LocalStrapiDestinationProvider implements IDestinationProvider {
return restore.deleteRecords(this.strapi, this.options.restore); return restore.deleteRecords(this.strapi, this.options.restore);
} }
async rollback(e: Error): Promise<void> {
await this.transaction(async () => {
throw e;
});
}
async beforeTransfer() { async beforeTransfer() {
if (!this.strapi) { if (!this.strapi) {
throw new Error('Strapi instance not found'); throw new Error('Strapi instance not found');

View File

@ -30,6 +30,7 @@ export const createTransaction = async (strapi: Strapi) => {
const res = await fn(trx); const res = await fn(trx);
e.emit(uuid, { data: res }); e.emit(uuid, { data: res });
} catch (error) { } catch (error) {
await trx.rollback();
e.emit(uuid, { error }); e.emit(uuid, { error });
} }
} }
@ -54,7 +55,7 @@ export const createTransaction = async (strapi: Strapi) => {
} }
if (error) { if (error) {
reject(data); reject(error);
} }
resolve(undefined); resolve(undefined);
}); });