2020-04-29 16:44:27 +01:00
|
|
|
const Promise = require('bluebird');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const fixtures = require('../../schema/fixtures');
|
2020-05-25 03:48:50 -05:00
|
|
|
const {logging} = require('../../../lib/common');
|
2016-10-12 17:18:57 +02:00
|
|
|
|
2017-12-05 09:14:55 +01:00
|
|
|
module.exports.config = {
|
|
|
|
transaction: true
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.up = function insertFixtures(options) {
|
2020-04-29 16:44:27 +01:00
|
|
|
const localOptions = _.merge({
|
2018-07-24 14:37:17 +02:00
|
|
|
context: {internal: true},
|
|
|
|
migrating: true
|
2016-10-12 17:18:57 +02:00
|
|
|
}, options);
|
|
|
|
|
|
|
|
return Promise.mapSeries(fixtures.models, function (model) {
|
2020-05-25 03:48:50 -05:00
|
|
|
logging.info('Model: ' + model.name);
|
2017-06-13 16:27:42 +07:00
|
|
|
|
2016-10-12 17:18:57 +02:00
|
|
|
return fixtures.utils.addFixturesForModel(model, localOptions);
|
|
|
|
}).then(function () {
|
|
|
|
return Promise.mapSeries(fixtures.relations, function (relation) {
|
2020-05-25 03:48:50 -05:00
|
|
|
logging.info('Relation: ' + relation.from.model + ' to ' + relation.to.model);
|
2016-10-12 17:18:57 +02:00
|
|
|
return fixtures.utils.addFixturesForRelation(relation, localOptions);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|