Skip to content

Commit

Permalink
allow files with specified extensions to be included in migrator list
Browse files Browse the repository at this point in the history
  • Loading branch information
benkitzelman committed May 26, 2021
1 parent 1f5c88e commit 9103ce7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
11 changes: 5 additions & 6 deletions lib/migrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function Migrator(driver, opts) {
this.driver = driver;
this.dir = (opts.dir || 'migrations');
this.coffee = (opts.coffee || false);
this.extensions = (opts.extensions || ['js', this.coffee ? 'coffee' : null]).filter(Boolean);
this.logger = (opts.logger || log);
this.dsl = new MigrationDsl(this.driver);
this.migration = new Migration(this.dsl, this.logger);
Expand Down Expand Up @@ -111,12 +112,10 @@ Migrator.prototype.mkdir = function(done) {
Migrator.prototype.loadModules = function() {
var self = this;
return fs.readdirSync(this.dir).filter(function(file) {
if (self.coffee) {
return file.match(/^\d+.*\.coffee$/);
}
else {
return file.match(/^\d+.*\.js$/);
}

const regex = new RegExp(`^\\d+.*\\.(${ self.extensions.join('|') })$`);
return file.match(regex);

}).sort().map(function(file) {
var mod = require(path.join(process.cwd(), self.dir, file));
return { file: file, up: mod.up, down: mod.down };
Expand Down
1 change: 0 additions & 1 deletion test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var util = require('util');
var path = require('path');
var orm = require('orm');
var rimraf = require('rimraf');
var common = module.exports;
var async = require('async');


Expand Down

0 comments on commit 9103ce7

Please sign in to comment.