Skip to content

Commit

Permalink
Merge cb4c448 into a589520
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelzor committed Nov 16, 2018
2 parents a589520 + cb4c448 commit 319b770
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
18 changes: 9 additions & 9 deletions src/migrate/Migrator.js
Expand Up @@ -190,15 +190,14 @@ export default class Migrator {
this._getLock(trx)
// When there is a wrapping transaction, some migrations
// could have been done while waiting for the lock:
.then(
() =>
trx
? migrationListResolver.listCompleted(
this.config.tableName,
this.config.schemaName,
trx
)
: []
.then(() =>
trx
? migrationListResolver.listCompleted(
this.config.tableName,
this.config.schemaName,
trx
)
: []
)
.then(
(completed) =>
Expand Down Expand Up @@ -336,6 +335,7 @@ export default class Migrator {
// We're going to run each of the migrations in the current "up".
current = current
.then(() => {
this._activeMigration.fileName = name;
if (
!trx &&
this._useTransaction(migrationContent, disableTransactions)
Expand Down
27 changes: 20 additions & 7 deletions test/integration/migrate/index.js
Expand Up @@ -174,17 +174,30 @@ module.exports = function(knex) {
});
});

it('should release lock if non-locking related error is thrown', function() {
return knex.migrate
.latest({ directory: 'test/integration/migrate/test' })
it('should report failing migration', function() {
const migrator = knex.migrate;
return migrator
.latest({ directory: 'test/integration/migrate/test_with_invalid' })
.then(function() {
throw new Error('then should not execute');
})
.catch(function(error) {
// This will fail because of the invalid migration
expect(error).to.have.property('message');
return knex('knex_migrations_lock').select('*');
})
expect(error)
.to.have.property('message')
.that.includes('unknown_table');
expect(migrator)
.to.have.property('_activeMigration')
.to.have.property(
'fileName',
'20150109002832_invalid_migration.js'
);
});
});

it('should release lock if non-locking related error is thrown', function() {
return knex('knex_migrations_lock')
.select('*')
.then(function(data) {
expect(data[0].is_locked).to.not.be.ok;
});
Expand Down Expand Up @@ -606,7 +619,7 @@ module.exports = function(knex) {

it('should not create unexpected tables', function() {
const table = 'migration_test_2_1';
knex.schema.hasTable(table).then(function(exists) {
return knex.schema.hasTable(table).then(function(exists) {
expect(exists).to.equal(false);
});
});
Expand Down

0 comments on commit 319b770

Please sign in to comment.