Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New config option to disable validateMigrationsList() #3448

Merged
merged 2 commits into from Oct 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -1025,4 +1025,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