Skip to content

Commit

Permalink
feat(ignored files): warn about ignored files in migrations directory
Browse files Browse the repository at this point in the history
@yannvr pointed out in #108 that if there is some extra files in migrations
directory, it might be a sign of invalid pattern. In the most common use case,
there is only migrations in migrations directory. => If there is other files,
the pattern is probably filtering out some migrations.
  • Loading branch information
jukkah committed Apr 22, 2017
1 parent c09d4dd commit 890e5e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,11 @@ module.exports = redefine.Class(/** @lends Umzug.prototype */ {
.promisify(fs.readdir)(this.options.migrations.path)
.bind(this)
.filter(function (file) {
return this.options.migrations.pattern.test(file);
if(!this.options.migrations.pattern.test(file)) {
this.log('File: ' + file + ' does not match pattern: ' + this.options.migrations.pattern);
return false;
}
return true;
})
.map(function (file) {
return path.resolve(this.options.migrations.path, file);
Expand Down
14 changes: 8 additions & 6 deletions test/index/execute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ describe('execute', function () {
.then(function () {
expect(this.upStub.callCount).to.equal(1);
expect(this.downStub.callCount).to.equal(0);
expect(this.logSpy.callCount).to.equal(2);
expect(this.logSpy.getCall(0).args[0]).to.equal('== 123-migration: migrating =======');
expect(this.logSpy.getCall(1).args[0]).to.match(/== 123-migration: migrated \(0\.0\d\ds\)/);
expect(this.logSpy.callCount).to.equal(3);
expect(this.logSpy.getCall(0).args[0]).to.match(/File: \.gitkeep does not match pattern: .+/);
expect(this.logSpy.getCall(1).args[0]).to.equal('== 123-migration: migrating =======');
expect(this.logSpy.getCall(2).args[0]).to.match(/== 123-migration: migrated \(0\.0\d\ds\)/);
expect(this.migratingEventSpy.calledWith('123-migration')).to.equal(true);
expect(this.migratedEventSpy.calledWith('123-migration')).to.equal(true);
});
Expand All @@ -59,9 +60,10 @@ describe('execute', function () {
.then(function () {
expect(this.upStub.callCount).to.equal(0);
expect(this.downStub.callCount).to.equal(1);
expect(this.logSpy.callCount).to.equal(2);
expect(this.logSpy.getCall(0).args[0]).to.equal('== 123-migration: reverting =======');
expect(this.logSpy.getCall(1).args[0]).to.match(/== 123-migration: reverted \(0\.0\d\ds\)/);
expect(this.logSpy.callCount).to.equal(3);
expect(this.logSpy.getCall(0).args[0]).to.match(/File: \.gitkeep does not match pattern: .+/);
expect(this.logSpy.getCall(1).args[0]).to.equal('== 123-migration: reverting =======');
expect(this.logSpy.getCall(2).args[0]).to.match(/== 123-migration: reverted \(0\.0\d\ds\)/);
expect(this.revertingEventSpy.calledWith('123-migration')).to.equal(true);
expect(this.revertedEventSpy.calledWith('123-migration')).to.equal(true);
});
Expand Down

0 comments on commit 890e5e1

Please sign in to comment.