Skip to content

Commit

Permalink
Fixes behavior when last run migration file is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd committed Apr 20, 2018
1 parent dbcf228 commit a3766db
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function migrate (set, direction, migrationName, fn) {
}

lastRunIndex = positionOfMigration(set.migrations, set.lastRun)

migrations = (direction === 'up' ? upMigrations : downMigrations)(set, lastRunIndex, toIndex)

function next (migration) {
Expand Down Expand Up @@ -114,8 +115,12 @@ function downMigrations (set, lastRunIndex, toIndex) {
*/

function positionOfMigration (migrations, title) {
var lastTimestamp
for (var i = 0; i < migrations.length; ++i) {
lastTimestamp = migrations[i].timestamp ? i : lastTimestamp

This comment has been minimized.

Copy link
@wookieb

wookieb Sep 5, 2018

Now this function never returns "-1" and line 12 in this file relies on it... Basically that change completely broke the function that suppose to return position of migration for given title but it always fails to do so.

This comment has been minimized.

Copy link
@wesleytodd

wesleytodd Sep 5, 2018

Author Collaborator

Yeah it looks like you might be right on that. There was another error condition which this fixed, and we must be missing tests around the "migrate to a title" functionality. I would be happy to accept a PR with a test and a fix for this. I probably wont be able to do it myself for the next week or so, but I could merge and publish a fix.

if (migrations[i].title === title) return i
}
return -1

// If titled migration was missing use last timestamped
return lastTimestamp
}

0 comments on commit a3766db

Please sign in to comment.