Skip to content

Commit

Permalink
Ignore missing files when run with --force
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd committed Apr 20, 2018
1 parent a3766db commit 00c201d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion bin/migrate-down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ program
.option('--matches <glob>', 'A glob pattern to filter migration files', '*')
.option('--compiler <ext:module>', 'Use the given module to compile files')
.option('--env [name]', 'Use dotenv to load an environment file')
.option('-F, --force', 'Force through the command, ignoring warnings')
.parse(process.argv)

// Change the working dir
Expand Down Expand Up @@ -52,7 +53,8 @@ var store = new Store(program.stateFile)
migrate.load({
stateStore: store,
migrationsDirectory: program.migrationsDir,
filterFunction: minimatch.filter(program.matches)
filterFunction: minimatch.filter(program.matches),
ignoreMissing: program.force
}, function (err, set) {
if (err) {
log.error('error', err)
Expand Down
5 changes: 3 additions & 2 deletions bin/migrate-up
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ program
.option('-f, --state-file <path>', 'Set path to state file', '.migrate')
.option('-s, --store <store>', 'Set the migrations store', path.join(__dirname, '..', 'lib', 'file-store'))
.option('--clean', 'Tears down the migration state before running up')
.option('--force', 'Force through the command, ignoring warnings')
.option('-F, --force', 'Force through the command, ignoring warnings')
.option('--init', 'Runs init for the store')
.option('--migrations-dir <dir>', 'Change the migrations directory name', 'migrations')
.option('--matches <glob>', 'A glob pattern to filter migration files', '*')
Expand Down Expand Up @@ -78,7 +78,8 @@ function loadAndGo () {
migrate.load({
stateStore: store,
migrationsDirectory: program.migrationsDir,
filterFunction: minimatch.filter(program.matches)
filterFunction: minimatch.filter(program.matches),
ignoreMissing: program.force
}, function (err, set) {
if (err) {
log.error('error', err)
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ exports.load = function (options, fn) {
store: store,
migrationsDirectory: opts.migrationsDirectory,
filterFunction: opts.filterFunction,
sortFunction: opts.sortFunction
sortFunction: opts.sortFunction,
ignoreMissing: opts.ignoreMissing
}, function (err) {
fn(err, set)
})
Expand Down
4 changes: 2 additions & 2 deletions lib/load-migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function loadMigrationsIntoSet (options, fn) {
}
var set = opts.set
var store = opts.store
var ignoreMissing = !!opts.ignoreMissing
var migrationsDirectory = path.resolve(opts.migrationsDirectory || 'migrations')
var filterFn = opts.filterFunction || (() => true)
var sortFn = opts.sortFunction || function (m1, m2) {
Expand Down Expand Up @@ -53,8 +54,7 @@ function loadMigrationsIntoSet (options, fn) {
// Fill in timestamp from state, or error if missing
state.migrations && state.migrations.forEach(function (m) {
if (m.timestamp !== null && !migMap[m.title]) {
// @TODO is this the best way to handle this?
return fn(new Error('Missing migration file: ' + m.title))
return ignoreMissing ? null : fn(new Error('Missing migration file: ' + m.title))
} else if (!migMap[m.title]) {
// Migration existed in state file, but was not run and not loadable
return
Expand Down

0 comments on commit 00c201d

Please sign in to comment.