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
|
|
|
|
|
2016-03-29 16:14:44 +03:00
|
|
|
var sequence = require('../../../utils/sequence'),
|
|
|
|
versioning = require('../../schema').versioning,
|
|
|
|
fixtureUtils = require('./utils'),
|
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);
|
2016-03-29 16:14:44 +03:00
|
|
|
return sequence(tasks, fixtureUtils.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-29 16:14:44 +03:00
|
|
|
return sequence(ops, fixtureUtils.modelOptions, logger);
|
2016-02-25 10:10:36 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = update;
|