mirror of
https://github.com/strapi/strapi.git
synced 2025-08-08 00:37:38 +00:00

* fix alter-column db migration Signed-off-by: Pierre Noël <petersg83@gmail.com> * refacto of data migration + fix sqlite dp migration Signed-off-by: Pierre Noël <petersg83@gmail.com> * refacto create-migration-runner Signed-off-by: Pierre Noël <petersg83@gmail.com> * fix migration Signed-off-by: Pierre Noël <petersg83@gmail.com> * refacto Signed-off-by: Pierre Noël <petersg83@gmail.com>
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;
|