Ghost/core/server/data/migration/fixtures/update.js
Hannah Wolfe d16433085f Improve fixtures & population code
refs #6301

- The order of model fixtures matters, so they should be in an array
- By splitting out the population code into a utils file, it'll be possible to use this to do updates as well
- This should make it much easier to do permissions updates in future
2016-03-31 11:48:44 +01:00

41 lines
1.2 KiB
JavaScript

// # 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'),
versioning = require('../../schema').versioning,
fixtureUtils = require('./utils'),
// Public
update;
/**
* ## Update
* Handles doing subsequent updates for versions
*
* @param {Array} versions
* @param {{info: logger.info, warn: logger.warn}} logger
* @returns {Promise<*>}
*/
update = function update(versions, logger) {
logger.info('Running fixture updates');
var ops = versions.reduce(function updateToVersion(ops, version) {
var tasks = versioning.getUpdateFixturesTasks(version, logger);
if (tasks && tasks.length > 0) {
ops.push(function runVersionTasks() {
logger.info('Updating fixtures to ' + version);
return sequence(tasks, fixtureUtils.modelOptions, logger);
});
}
return ops;
}, []);
return sequence(ops, fixtureUtils.modelOptions, logger);
};
module.exports = update;