mirror of
https://github.com/strapi/strapi.git
synced 2025-08-09 01:07:27 +00:00
34 lines
708 B
JavaScript
34 lines
708 B
JavaScript
![]() |
'use strict';
|
||
|
|
||
|
const _ = require('lodash');
|
||
|
|
||
|
const createMigrationRunner = (migrationFunction, { hooks = [] } = {}) => {
|
||
|
const beforeHook = async options => {
|
||
|
for (const migration of hooks) {
|
||
|
if (_.isFunction(migration.before)) {
|
||
|
await migration.before(options);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const afterHook = async options => {
|
||
|
for (const migration of hooks.slice(0).reverse()) {
|
||
|
if (_.isFunction(migration.after)) {
|
||
|
await migration.after(options);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const run = async options => {
|
||
|
await beforeHook(options);
|
||
|
await migrationFunction(options);
|
||
|
await afterHook(options);
|
||
|
};
|
||
|
|
||
|
return {
|
||
|
run,
|
||
|
};
|
||
|
};
|
||
|
|
||
|
module.exports = createMigrationRunner;
|