Skip to content

Commit

Permalink
disable_migrations_list_validation_feature (#3448)
Browse files Browse the repository at this point in the history
  • Loading branch information
arrilot authored and kibertoad committed Oct 12, 2019
1 parent 4a71315 commit 6b9fb0e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/migrate/Migrator.js
Expand Up @@ -65,7 +65,9 @@ class Migrator {
return migrationListResolver
.listAllAndCompleted(this.config, this.knex)
.then((value) => {
validateMigrationList(this.config.migrationSource, value);
if (!this.config.disableMigrationsListValidation) {
validateMigrationList(this.config.migrationSource, value);
}
return value;
})
.then(([all, completed]) => {
Expand Down Expand Up @@ -104,7 +106,9 @@ class Migrator {
return migrationListResolver
.listAllAndCompleted(this.config, this.knex)
.then((value) => {
validateMigrationList(this.config.migrationSource, value);
if (!this.config.disableMigrationsListValidation) {
validateMigrationList(this.config.migrationSource, value);
}
return value;
})
.then(([all, completed]) => {
Expand Down Expand Up @@ -170,7 +174,9 @@ class Migrator {
migrationListResolver
.listAllAndCompleted(this.config, this.knex)
.then((value) => {
validateMigrationList(this.config.migrationSource, value);
if (!this.config.disableMigrationsListValidation) {
validateMigrationList(this.config.migrationSource, value);
}
return value;
})
.then((val) => {
Expand Down Expand Up @@ -198,7 +204,9 @@ class Migrator {
return migrationListResolver
.listAllAndCompleted(this.config, this.knex)
.then((value) => {
validateMigrationList(this.config.migrationSource, value);
if (!this.config.disableMigrationsListValidation) {
validateMigrationList(this.config.migrationSource, value);
}
return value;
})
.then(([all, completed]) => {
Expand Down Expand Up @@ -267,7 +275,10 @@ class Migrator {
this.config,
this.knex
);
validateMigrationList(this.config.migrationSource, [all, completed]);

if (!this.config.disableMigrationsListValidation) {
validateMigrationList(this.config.migrationSource, [all, completed]);
}

const newMigrations = getNewMigrations(
this.config.migrationSource,
Expand Down
1 change: 1 addition & 0 deletions lib/migrate/configuration-merger.js
Expand Up @@ -10,6 +10,7 @@ const CONFIG_DEFAULT = Object.freeze({
schemaName: null,
directory: './migrations',
disableTransactions: false,
disableMigrationsListValidation: false,
sortDirsSeparately: false,
});

Expand Down
21 changes: 21 additions & 0 deletions test/integration/migrate/index.js
Expand Up @@ -1036,4 +1036,25 @@ module.exports = function(knex) {
});
});
});

describe('knex.migrate.latest with disableValidateMigrationList', function() {
it('should not fail if there is a missing migration', () => {
return knex.migrate
.latest({
directory: 'test/integration/migrate/test',
})
.then(() => {
return knex.migrate.latest({
directory:
'test/integration/migrate/test_with_missing_first_migration',
disableMigrationsListValidation: true,
});
})
.finally(() => {
return knex.migrate.rollback({
directory: 'test/integration/migrate/test',
});
});
});
});
};
@@ -0,0 +1,33 @@
'use strict';

exports.up = function(knex, promise) {
const tableName2 = knex.userParams.customTableName || 'migration_test_2_1';
return knex.schema
.createTable('migration_test_2', function(t) {
t.increments();
t.string('name');
})
.then(() =>
knex.schema.createTable(tableName2, function(t) {
t.increments();
t.string('name');
})
)
.then(() => {
return knex.schema.table('migration_test_1', function(t) {
t.integer('age');
});
});
};

exports.down = function(knex, promise) {
const tableName2 = knex.userParams.customTableName || 'migration_test_2_1';
return knex.schema
.dropTable('migration_test_2')
.then(() => knex.schema.dropTable(tableName2))
.then(() => {
return knex.schema.table('migration_test_1', function(t) {
t.dropColumn('age');
});
});
};
1 change: 1 addition & 0 deletions types/index.d.ts
Expand Up @@ -1810,6 +1810,7 @@ declare namespace Knex {
tableName?: string;
schemaName?: string;
disableTransactions?: boolean;
disableMigrationsListValidation?: boolean;
sortDirsSeparately?: boolean;
loadExtensions?: string[];
migrationSource?: any;
Expand Down

0 comments on commit 6b9fb0e

Please sign in to comment.