mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 15:36:28 +00:00
data duplicator runs in transaction
This commit is contained in:
@@ -207,11 +207,18 @@ export class DataDuplicator {
|
|||||||
async run() {
|
async run() {
|
||||||
this.createPlan();
|
this.createPlan();
|
||||||
|
|
||||||
|
await runCommandOnDriver(this.pool, this.driver, dmp => dmp.beginTransaction());
|
||||||
|
try {
|
||||||
for (const item of this.itemPlan) {
|
for (const item of this.itemPlan) {
|
||||||
const stats = await item.runImport();
|
const stats = await item.runImport();
|
||||||
logger.info(
|
logger.info(
|
||||||
`Duplicated ${item.name}, inserted ${stats.inserted} rows, mapped ${stats.mapped} rows, missing ${stats.missing} rows`
|
`Duplicated ${item.name}, inserted ${stats.inserted} rows, mapped ${stats.mapped} rows, missing ${stats.missing} rows`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error({ err }, 'Failed duplicator job, rollbacking');
|
||||||
|
await runCommandOnDriver(this.pool, this.driver, dmp => dmp.rollbackTransaction());
|
||||||
|
}
|
||||||
|
await runCommandOnDriver(this.pool, this.driver, dmp => dmp.commitTransaction());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user