Pierre Noël ff5307e8b6
fix altercolumns db migration (#8565)
* 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>
2020-11-06 14:27:57 +01:00

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;