"use strict"; var db = require('./database'), async = require('async'), winston = require('winston'), User = require('./user'), Topics = require('./topics'), Posts = require('./posts'), Groups = require('./groups'), Utils = require('../public/src/utils'), Upgrade = {}, minSchemaDate = new Date(2014, 0, 4).getTime(), // This value gets updated every new MINOR version schemaDate, thisSchemaDate; Upgrade.check = function(callback) { // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema var latestSchema = new Date(2014, 0, 19, 22, 19).getTime(); db.get('schemaDate', function(err, value) { if (parseInt(value, 10) >= latestSchema) { callback(true); } else { callback(false); } }); }; Upgrade.upgrade = function(callback) { var updatesMade = false; winston.info('Beginning database schema update'); async.series([ function(next) { // Prepare for upgrade & check to make sure the upgrade is possible db.get('schemaDate', function(err, value) { schemaDate = value; if (schemaDate >= minSchemaDate || schemaDate === null) { next(); } else { next(new Error('upgrade-not-possible')); } }); }, function(next) { thisSchemaDate = new Date(2014, 0, 5).getTime(); if (schemaDate < thisSchemaDate) { updatesMade = true; db.getListRange('categories:cid', 0, -1, function(err, cids) { if(err) { return next(err); } var timestamp = Date.now(); function upgradeCategory(cid, next) { db.getSetMembers('cid:' + cid + ':active_users', function(err, uids) { if(err) { return next(err); } db.delete('cid:' + cid + ':active_users', function(err) { if(err) { return next(err); } for(var i=0; i