mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-05 15:20:39 +01:00
changed file schema to be name only, storing them in object sets referencing their applicable versions
This commit is contained in:
@@ -4,19 +4,54 @@
|
||||
var async = require('async');
|
||||
var path = require('path');
|
||||
|
||||
var db = require('./database');
|
||||
var utils = require('../public/src/utils');
|
||||
|
||||
var Upgrade = {};
|
||||
var Upgrade = {
|
||||
available: [
|
||||
{
|
||||
version: "1.2.0",
|
||||
upgrades: ['category_recent_tids']
|
||||
},
|
||||
{
|
||||
version: "1.3.0",
|
||||
upgrades: ['favourites_to_bookmarks', 'sorted_sets_for_post_replies']
|
||||
},
|
||||
{
|
||||
version: "1.4.0",
|
||||
upgrades: ['global_and_user_language_keys', 'sorted_set_for_pinned_topics']
|
||||
},
|
||||
{
|
||||
version: "1.5.0",
|
||||
upgrades: ['flags_refactor']
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
Upgrade.run = function (callback) {
|
||||
process.stdout.write('\nParsing upgrade scripts... ');
|
||||
var queue = [];
|
||||
var skipped = 0;
|
||||
|
||||
utils.walk(path.join(__dirname, './upgrades'), function (err, files) {
|
||||
// Retrieve list of upgrades that have already been run
|
||||
db.getSortedSetRange('schemaLog', 0, -1, function (err, completed) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
Upgrade.process(files, callback);
|
||||
queue = Upgrade.available.reduce(function (memo, cur) {
|
||||
cur.upgrades.forEach(function (filename) {
|
||||
if (completed.indexOf(filename) === -1) {
|
||||
memo.push(path.join(__dirname, './upgrades', filename));
|
||||
} else {
|
||||
++skipped;
|
||||
}
|
||||
});
|
||||
|
||||
return memo;
|
||||
}, queue);
|
||||
|
||||
Upgrade.process(queue, skipped, callback);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -35,12 +70,12 @@ Upgrade.runSingle = function (query, callback) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
Upgrade.process(files, callback);
|
||||
Upgrade.process(files, 0, callback);
|
||||
});
|
||||
};
|
||||
|
||||
Upgrade.process = function (files, callback) {
|
||||
process.stdout.write('OK'.green + String(' ' + files.length).cyan + ' script(s) found\n'.cyan);
|
||||
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);
|
||||
|
||||
// Do I need to sort the files here? we'll see.
|
||||
// sort();
|
||||
@@ -58,6 +93,9 @@ Upgrade.process = function (files, callback) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
// Record success in schemaLog
|
||||
db.sortedSetAdd('schemaLog', Date.now(), path.basename(file, '.js'));
|
||||
|
||||
process.stdout.write('OK\n'.green);
|
||||
next();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user