diff --git a/lib/runner.js b/lib/runner.js index 0f42caae..f46d1162 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -1,4 +1,3 @@ -import _ from 'lodash'; import path from 'path'; import crypto from 'crypto'; import fs from 'fs'; @@ -25,15 +24,31 @@ const runOnColumn = 'run_on'; const loadMigrationFiles = (db, options) => readdir(`${options.dir}/`) .then(files => - _.chain(files) + Promise.all(files.map(file => + new Promise((resolve, reject) => + fs.lstat(`${options.dir}/${file}`, (err, stats) => ( + err + ? reject(err) + : resolve(stats.isFile() ? file : null) + ))) + )) + ) + .then(files => + files + .filter(i => i) .map((file) => { const file_path = `${options.dir}/${file}`; // eslint-disable-next-line global-require,import/no-dynamic-require const actions = require(path.relative(__dirname, file_path)); return new Migration(db, file_path, actions, options); }) - .sortBy('name') - .value() + .sort((m1, m2) => ( + m1.name < m2.name // eslint-disable-line no-nested-ternary + ? -1 + : m1.name > m2.name + ? 1 + : 0 + )) ) .catch((err) => { throw new Error(`Can't get migration files: ${err.stack}`);