2016-02-25 10:10:36 +03:00
|
|
|
// # Update Fixtures
|
|
|
|
// This module handles updating fixtures.
|
|
|
|
// This is done manually, through a series of files stored in an adjacent folder
|
|
|
|
// E.g. if we update to version 004, all the tasks in /004/ are executed
|
|
|
|
|
|
|
|
var sequence = require('../../../utils/sequence'),
|
2016-03-14 20:39:00 +03:00
|
|
|
versioning = require('../../schema').versioning,
|
2016-02-25 10:10:36 +03:00
|
|
|
|
|
|
|
// Private
|
2016-03-13 23:49:30 +03:00
|
|
|
modelOptions = {context: {internal: true}},
|
2016-02-25 10:10:36 +03:00
|
|
|
|
|
|
|
// Public
|
|
|
|
update;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ## Update
|
|
|
|
* Handles doing subsequent updates for versions
|
|
|
|
*
|
|
|
|
* @param {Array} versions
|
2016-03-21 15:44:23 +03:00
|
|
|
* @param {{info: logger.info, warn: logger.warn}} logger
|
2016-02-25 10:10:36 +03:00
|
|
|
* @returns {Promise<*>}
|
|
|
|
*/
|
2016-03-21 15:44:23 +03:00
|
|
|
update = function update(versions, logger) {
|
|
|
|
logger.info('Running fixture updates');
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-14 20:39:00 +03:00
|
|
|
var ops = versions.reduce(function updateToVersion(ops, version) {
|
2016-03-21 15:44:23 +03:00
|
|
|
var tasks = versioning.getUpdateFixturesTasks(version, logger);
|
2016-02-25 10:10:36 +03:00
|
|
|
|
|
|
|
if (tasks && tasks.length > 0) {
|
2016-03-14 20:39:00 +03:00
|
|
|
ops.push(function runVersionTasks() {
|
2016-03-21 15:44:23 +03:00
|
|
|
logger.info('Updating fixtures to ' + version);
|
|
|
|
return sequence(tasks, modelOptions, logger);
|
2016-02-25 10:10:36 +03:00
|
|
|
});
|
|
|
|
}
|
2016-03-14 20:39:00 +03:00
|
|
|
|
|
|
|
return ops;
|
|
|
|
}, []);
|
2016-02-25 10:10:36 +03:00
|
|
|
|
2016-03-21 15:44:23 +03:00
|
|
|
return sequence(ops, modelOptions, logger);
|
2016-02-25 10:10:36 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = update;
|