@wmfs/pg-delta-file
Advanced tools
Comparing version 1.32.1 to 1.33.0
@@ -0,1 +1,19 @@ | ||
# [1.33.0](https://github.com/wmfs/pg-delta-file/compare/v1.32.1...v1.33.0) (2019-12-01) | ||
### ✨ Features | ||
* Report delta file progress through options.progressCallback ([](https://github.com/wmfs/pg-delta-file/commit/0046be7)) | ||
### 🐛 Bug Fixes | ||
* Pass export complete flag to progressCallback ([](https://github.com/wmfs/pg-delta-file/commit/c53e95a)) | ||
* Prevent undefined when no progress callback provided. ([](https://github.com/wmfs/pg-delta-file/commit/816d05e)) | ||
### 💎 Styles | ||
* Lint fix ([](https://github.com/wmfs/pg-delta-file/commit/8acfcba)) | ||
## [1.32.1](https://github.com/wmfs/pg-delta-file/compare/v1.32.0...v1.32.1) (2019-10-03) | ||
@@ -2,0 +20,0 @@ |
@@ -7,2 +7,3 @@ const fs = require('fs') | ||
module.exports = async function generateDelta (options) { | ||
const progressCallback = options.progressCallback ? options.progressCallback : () => {} | ||
const deltaFileWriteStream = createOutputStream(options.outputFilepath, options.dryrun) | ||
@@ -24,2 +25,3 @@ | ||
} finally { | ||
progressCallback(info, true) | ||
await new Promise((resolve, reject) => deltaFileWriteStream.end(err => err ? reject(err) : resolve())) | ||
@@ -51,2 +53,3 @@ } | ||
function extractModel (info, model, options, outStream) { | ||
const progressCallback = options.progressCallback ? options.progressCallback : () => {} | ||
const modified = options.modifiedColumnName || '_modified' | ||
@@ -64,3 +67,3 @@ | ||
dbStream.on('error', reject) | ||
dbStream.on('end', resolve) | ||
dbStream.on('end', () => { progressCallback(info, false); resolve() }) | ||
}) | ||
@@ -67,0 +70,0 @@ } |
@@ -14,2 +14,3 @@ const Transform = require('stream').Transform | ||
this.filterFn = options.filterFunction ? options.filterFunction : () => true | ||
this.progressCallback = options.progressCallback | ||
@@ -74,4 +75,16 @@ this.transformers = options.csvExtracts[model].map(csvColumnSource => { | ||
) | ||
this.progress() | ||
} // _transform | ||
progress () { | ||
if (!this.progressCallback) return | ||
// report every 1000 rows | ||
const c = this.modelInfo.totalCount | ||
if (Math.trunc(c / 1000) === (c / 1000)) { | ||
this.progressCallback(this.info, false) | ||
} | ||
} | ||
bumpRowCount () { | ||
@@ -78,0 +91,0 @@ this.info.totalCount++ |
{ | ||
"name": "@wmfs/pg-delta-file", | ||
"version": "1.32.1", | ||
"version": "1.33.0", | ||
"description": "Outputs change-only-update CSV files (or “delta” files) that contain all the necessary actions required to re-synchronize rows in a cloned table.", | ||
@@ -5,0 +5,0 @@ "author": "West Midlands Fire Service", |
@@ -276,5 +276,12 @@ /* eslint-env mocha */ | ||
let callbackInfo = null | ||
const callbackProgress = [] | ||
test.delta.client = client | ||
test.delta.outputFilepath = outputFile | ||
test.delta.dryrun = false | ||
test.delta.progressCallback = (info, complete) => { | ||
callbackInfo = info | ||
callbackProgress.push(complete) | ||
} | ||
@@ -287,3 +294,9 @@ const info = await generateDelta( | ||
expect(info).to.eql(test.info) | ||
expect(info).to.eql(callbackInfo) | ||
const expectedProgress = callbackProgress.map(() => false) | ||
expectedProgress[callbackProgress.length - 1] = true | ||
expect(expectedProgress).to.eql(callbackProgress) | ||
const output = readRecords(outputFile) | ||
@@ -290,0 +303,0 @@ const expected = readRecords(expectedFile) |
43619
538