added logic to handle backwards compatibility with old schemaDate method of tracking upgrade scripts

v1.18.x
Julian Lam 8 years ago
parent 767705085b
commit c323a813c0

@ -150,14 +150,26 @@ Upgrade.runSingle = function (query, callback) {
Upgrade.process = function (files, skipCount, callback) { Upgrade.process = function (files, skipCount, callback) {
process.stdout.write('OK'.green + ' | '.reset + String(files.length).cyan + ' script(s) found'.cyan + (skipCount > 0 ? ', '.cyan + String(skipCount).cyan + ' skipped'.cyan : '') + '\n'.reset); process.stdout.write('OK'.green + ' | '.reset + String(files.length).cyan + ' script(s) found'.cyan + (skipCount > 0 ? ', '.cyan + String(skipCount).cyan + ' skipped'.cyan : '') + '\n'.reset);
async.waterfall([
async.apply(db.get, 'schemaDate'),
function (schemaDate, next) {
var schemaTime = new Date(schemaDate);
async.eachSeries(files, function (file, next) { async.eachSeries(files, function (file, next) {
var scriptExport = require(file); var scriptExport = require(file);
var date = new Date(scriptExport.timestamp); var date = new Date(scriptExport.timestamp);
process.stdout.write(' → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '... '); process.stdout.write(' → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '... ');
// For backwards compatibility, cross-reference with schemaDate (if found). If a script's date is older, skip it
if (scriptExport.timestamp <= schemaTime) {
process.stdout.write('skipped\n'.grey);
db.sortedSetAdd('schemaLog', Date.now(), path.basename(file, '.js'));
return next();
}
// Do the upgrade... // Do the upgrade...
scriptExport.method(function (err) { scriptExport.method(function (err, skipped) {
if (err) { if (err) {
process.stdout.write('error\n'.red); process.stdout.write('error\n'.red);
return next(err); return next(err);
@ -171,12 +183,14 @@ Upgrade.process = function (files, skipCount, callback) {
}); });
}, function (err) { }, function (err) {
if (err) { if (err) {
return callback(err); return next(err);
} }
process.stdout.write('Upgrade complete!\n\n'.green); process.stdout.write('Upgrade complete!\n\n'.green);
callback(); next();
}); });
},
], callback);
}; };
module.exports = Upgrade; module.exports = Upgrade;

Loading…
Cancel
Save