diff --git a/src/upgrades/1.4.6/delete_sessions.js b/src/upgrades/1.4.6/delete_sessions.js new file mode 100644 index 0000000000..dd9cbb91e4 --- /dev/null +++ b/src/upgrades/1.4.6/delete_sessions.js @@ -0,0 +1,40 @@ +/* jslint node: true */ + +'use strict'; + +var db = require('../../database'); +var async = require('async'); + +module.exports = { + name: 'Delete accidentally long-lived sessions', + timestamp: Date.UTC(2017, 3, 16), + method: function (callback) { + var configJSON = require.main.require('./config.json'); + var isRedisSessionStore = configJSON.hasOwnProperty('redis'); + + async.waterfall([ + function (next) { + if (isRedisSessionStore) { + var rdb = require.main.require('./database/redis'); + var client = rdb.connect(); + async.waterfall([ + function (next) { + client.keys('sess:*', next); + }, + function (sessionKeys, next) { + async.eachSeries(sessionKeys, function (key, next) { + client.del(key, next); + }, next); + }, + ], function (err) { + next(err); + }); + } else { + db.client.collection('sessions').deleteMany({}, {}, function (err) { + next(err); + }); + } + }, + ], callback); + }, +};