Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongopatch

Package Overview
Dependencies
Maintainers
4
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongopatch - npm Package Compare versions

Comparing version 0.4.1 to 0.5.1

3

bin/mongopatch.js

@@ -115,2 +115,5 @@ #!/usr/bin/env node

delete opts[''];
delete opts.$0;
apply(argv._[0], opts);

2

package.json
{
"name": "mongopatch",
"version": "0.4.1",
"version": "0.5.1",
"repository": "git://github.com/e-conomic/mongopatch.git",

@@ -5,0 +5,0 @@ "description": "MongoDB patching tool",

@@ -15,3 +15,2 @@ mongopatch [![Build Status](https://travis-ci.org/e-conomic/mongopatch.png?branch=master)](https://travis-ci.org/e-conomic/mongopatch)

```javascript
module.exports = function(patch) {

@@ -83,2 +82,18 @@ // Specify which patching system version to use for this patch (required)

It's also possible to register `setup` and `teardown` hooks, executed before and after the patch is run. The `teardown` callback gets called with an additional stats object, containg accumulated details about the patch.
```javascript
patch.setup(function(callback) {
// Pass an error object as first argument to callback, to terminate execution.
callback();
});
```
```javascript
patch.teardown(function(stats, callback) {
// Stats contains details about execution time, number of modified documents and average speed.
callback();
});
```
Runing patches

@@ -85,0 +100,0 @@ --------------

@@ -24,3 +24,3 @@ var util = require('util');

var name = function(collection) {
return 'patch_' + moment().format('YYMMDD.HHmmss.SSS') + '_' + collection.toString();
return 'patch_' + moment().format('YYYYMMDD.HHmmss.SSS') + '_' + collection.toString();
};

@@ -33,6 +33,24 @@

var that = stream.passThrough({ objectMode: true });
var progress = {
total: 0,
count: 0,
modified: 0,
speed: 0,
remaining: 0,
eta: 0,
time: 0,
percentage: 100,
diff: {}
};
that.options = options;
that.db = applicationDb;
that.id = null;
that.version = function(version) {
that._version = version;
};
that.setup = function(callback) {
that._setup = callback;
};
that.update = function(collection, query, worker) {

@@ -56,6 +74,32 @@ if(!worker) {

};
that.version = function(version) {
that._version = version;
that.teardown = function(callback) {
that._teardown = callback;
};
var setup = function() {
if(!that._version || !semver.eq(that._version, packageJson.version)) {
return that.emit('error', new Error(util.format('Specified version (%s) does not match current system version (%s)',
that._version, packageJson.version)));
}
if(!that._update) {
return that.emit('error', new Error('Update missing'));
}
var callback = that._setup || function(fn) {
fn();
};
callback(function(err) {
if(err) {
return that.emit('error', err);
}
that.on('end', teardown);
that.on('data', function(data) {
progress = data.progress;
});
update();
});
};
var update = function() {

@@ -97,10 +141,27 @@ var collection = that._update.collection;

stream = stream.pipe(that);
stream
.pipe(that)
.resume();
});
};
var teardown = function() {
var callback = that._teardown || function(_, fn) {
fn();
};
stream.on('end', function() {
applicationDb.close();
logDb && logDb.close();
});
var stats = {
total: progress.count,
modified: progress.modified,
time: progress.time,
speed: progress.time ? (progress.count / progress.time) : 0,
diff: progress.diff
};
stream.resume();
callback(stats, function(err) {
if(err) {
return that.emit('error', err);
}
applicationDb.close();
logDb && logDb.close();
});

@@ -110,15 +171,4 @@ };

patch(that);
setup();
setImmediate(function() {
if(!that._version || !semver.eq(that._version, packageJson.version)) {
return that.emit('error', new Error(util.format('Specified version (%s) does not match current system version (%s)',
that._version, packageJson.version)));
}
if(!that._update) {
return that.emit('error', new Error('Update missing'));
}
update();
});
return that;

@@ -125,0 +175,0 @@ };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc