From f725e36523f3f2ddfc4ac9aa3009d3c6503916b4 Mon Sep 17 00:00:00 2001 From: John McLear Date: Thu, 24 Mar 2016 14:13:34 +0000 Subject: [PATCH] a script to remove old pad data, needs full testing --- bin/removeOldPadData.js | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 bin/removeOldPadData.js diff --git a/bin/removeOldPadData.js b/bin/removeOldPadData.js new file mode 100644 index 000000000..1f55eea0f --- /dev/null +++ b/bin/removeOldPadData.js @@ -0,0 +1,79 @@ +/* + This is a debug tool. It removes old pad data from a couch database +*/ + +//get the padID +var padId = process.argv[2]; + +//initalize the variables +var db, settings, keys, values; +var npm = require("../src/node_modules/npm"); +var async = require("../src/node_modules/async"); + +async.series([ + //load npm + function(callback) { + npm.load({}, function(er) { + callback(er); + }) + }, + //load modules + function(callback) { + settings = require('../src/node/utils/Settings'); + db = require('../src/node/db/DB'); + + //intallize the database + db.init(callback); + }, + //get the session info + function (callback){ + db.db.findKeys("pad:*",null, function(err, dbkeys){ + keys = dbkeys; + callback(); + }); + }, + function (callback) + { + values = {}; + async.eachSeries(keys, function(key, cb){ + db.db.get(key, function(err, value){ + // console.log("err", err); + // console.log("value", key, value); + values[key] = value; + cb(); + }); + }, function(){ + callback(); + }); + }, + // Removing all old pad data record + function (callback){ + async.each(keys, function(key, cb){ + console.log("Removing", key); + db.db.remove(key, function(err){ + if(err) console.log("err", err); + cb(); + }); + }, function(){ + callback(); + }); + }, + // Add latest data back in for a pad + function (callback){ + async.eachSeries(keys, function(key, cb){ + console.log("Adding data back in for", key); + db.db.set(key, values[key]); + cb(); + }, function(){ + callback(); + }); + } +], function (err) +{ + if(err) throw err; + else{ + console.log("finished"); + process.exit(0); + } +}); +