Skip to content

Commit

Permalink
Merge pull request #1 from locomote/allow-any-migration-file-ext
Browse files Browse the repository at this point in the history
Allow any migration file ext
  • Loading branch information
benkitzelman authored May 26, 2021
2 parents 1f5c88e + 670ab25 commit bb6670a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 47 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
80 changes: 44 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "migrate-orm2",
"version": "4.1.3",
"version": "4.1.4",
"description": "A library providing migrations using ORM2's model DSL leveraging Visionmedia's node-migrate.",
"main": "index.js",
"repository": {
Expand All @@ -18,13 +18,13 @@
"dependencies": {
"async": "~2.6.3",
"bluebird": "^3.5.1",
"lodash": "^4.17.20",
"lodash": "^4.17.21",
"mkdirp": "~0.5.5",
"sql-ddl-sync": "~0.3.16"
},
"devDependencies": {
"mocha": "8.3.2",
"mysql": "2.15.0",
"mysql": "^2.18.1",
"orm": "5.0.5",
"pg": "8.6.0",
"rimraf": "2.6.1",
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
3 changes: 2 additions & 1 deletion test/integration/add_drop_column_spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var _ = require('lodash');
var should = require('should');
var helpers = require('../helpers');
var Task = require('./../../');
Expand Down Expand Up @@ -57,7 +58,7 @@ describe('add/drop column dsl', function (done) {
function (err, result) {
should.not.exist(err);

should.equal(result[0].column_name, 'full_name')
should.equal(_.values(result[0])[0], 'full_name')
done();
}
);
Expand Down

0 comments on commit bb6670a

Please sign in to comment.