Skip to content

Node.js based forum software built for the modern web

upgrade script to clear sessions

barisusaklicf6c4667c8a7
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) {