From cf6c4667c8a7b364327be01fe47d90e9df7b736d Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 16 Apr 2017 15:31:50 -0400 Subject: [PATCH] upgrade script to clear sessions --- src/upgrade.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/upgrade.js b/src/upgrade.js index 0ab9984646..f7c20f3c89 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -12,7 +12,7 @@ var schemaDate; var thisSchemaDate; // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema -var latestSchema = Date.UTC(2017, 1, 28); +var latestSchema = Date.UTC(2017, 3, 16); Upgrade.check = function (callback) { db.get('schemaDate', function (err, value) { @@ -425,6 +425,50 @@ Upgrade.upgrade = function (callback) { next(); } }, + function (next) { + thisSchemaDate = Date.UTC(2017, 3, 16); + var schemaName = '[2017/4/16] Delete sessions'; + + if (schemaDate < thisSchemaDate) { + updatesMade = true; + winston.info(schemaName); + + var configJSON = require('../config.json'); + var isRedisSessionStore = configJSON.hasOwnProperty('redis'); + + async.waterfall([ + function (next) { + if (isRedisSessionStore) { + var rdb = 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').drop({}, function (err) { + next(err); + }); + } + }, + function (next) { + winston.info(schemaName + ' - done'); + Upgrade.update(thisSchemaDate, next); + }, + ], next); + } else { + winston.info(schemaName + ' - skipped!'); + next(); + } + }, // Add new schema updates here // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!! ], function (err) {