Ghost/core/server/data/migrations/init/2-create-fixtures.js
Aileen Nowak 57f8367cdf 🐛 Add published_at to post model fixtures (#8573)
closes #8562
- before we create our model fixtures, we assign a `published_at` property with a difference of 1 second for each blog post, so the `prev_post` and `next_post` helpers work correctly
2017-06-13 10:27:42 +01:00

31 lines
1.2 KiB
JavaScript

var Promise = require('bluebird'),
_ = require('lodash'),
fixtures = require('../../schema/fixtures'),
logging = require('../../../logging'),
moment = require('moment');
module.exports = function insertFixtures(options) {
var localOptions = _.merge({
context: {internal: true}
}, options);
return Promise.mapSeries(fixtures.models, function (model) {
logging.info('Model: ' + model.name);
// The Post model fixtures need a `published_at` date, where at least the seconds
// are different, otherwise `prev_post` and `next_post` helpers won't workd with
// them.
if (model.name === 'Post') {
_.forEach(model.entries, function (post, index) {
post.published_at = moment().add(index, 'seconds');
});
}
return fixtures.utils.addFixturesForModel(model, localOptions);
}).then(function () {
return Promise.mapSeries(fixtures.relations, function (relation) {
logging.info('Relation: ' + relation.from.model + ' to ' + relation.to.model);
return fixtures.utils.addFixturesForRelation(relation, localOptions);
});
});
};