Skip to content

Commit

Permalink
Changed init completion: ignore skipped tasks
Browse files Browse the repository at this point in the history
no issue

- might fix TryGhost/Ghost#10155
- the init completion is important, because as soon as you run `knex-migrator migrate`, knex-migrator would execute all missing migrations
- we should ignore the skipped tasks, because otherwise the following case does not work
  - you run `knex-migrator init`
  - the process get's destroyed
  - db is locked
  - one init script was executed
  - you release the lock
  - knex-migrator tells you to run "init"
  - you run it again
  - one task was skipped and the db migrations table is incomplete, because the init completion did not run
  • Loading branch information
kirrg001 committed Nov 13, 2018
1 parent 6ce7a2e commit 7501103
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ KnexMigrator.prototype.init = function init(options) {
}
})
.then(function () {
// CASE: re-run init and e.g. one migration was added to the init folder.
if (skippedTasks.length || skipInitCompletion) {
// CASE: you can disale init completion (that means, knex-migrator does not insert the existing
// migration scripts
if (skipInitCompletion) {
return Promise.resolve();
}

Expand All @@ -142,6 +143,7 @@ KnexMigrator.prototype.init = function init(options) {
let filesToMigrateTo = utils.readTasks(versionPath) || [];

return Promise.each(filesToMigrateTo, function (fileToMigrateTo) {
// CASE: check if migration exists, do not insert twice
return transacting('migrations')
.where('name', fileToMigrateTo.name)
.then(function (migrationExists) {
Expand Down

0 comments on commit 7501103

Please sign in to comment.