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

v1.18.x
Julian Lam
parent 767705085b
commit c323a813c0

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

Loading…
Cancel
Save