Pierre Noël 4a02c158b9
Fix migration when disabling dp on sqlite (#8768)
* fix migration disable dp on sqlite

Signed-off-by: Pierre Noël <petersg83@gmail.com>

* fix mongo test

Signed-off-by: Pierre Noël <petersg83@gmail.com>

* use context instead of migrationInfos

* refacto

* remove useless if
2020-12-17 12:33:00 +01:00

34 lines
789 B
JavaScript

'use strict';
const _ = require('lodash');
const createMigrationRunner = (migrationFunction, { hooks = [] } = {}, context = {}) => {
const beforeHook = async (options, context) => {
for (const migration of hooks) {
if (_.isFunction(migration.before)) {
await migration.before(options, context);
}
}
};
const afterHook = async (options, context) => {
for (const migration of hooks.slice(0).reverse()) {
if (_.isFunction(migration.after)) {
await migration.after(options, context);
}
}
};
const run = async options => {
await beforeHook(options, context);
await migrationFunction(options, context);
await afterHook(options, context);
};
return {
run,
};
};
module.exports = createMigrationRunner;