-
-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(check): add check functionality to determine migrations to run
Signed-off-by: RandomSeeded <nate@blend.com>
- Loading branch information
RandomSeeded
committed
Apr 9, 2018
1 parent
5ee386b
commit dffaace
Showing
7 changed files
with
172 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var path = require('path'); | ||
var log = require('db-migrate-shared').log; | ||
var assert = require('./helper/assert.js'); | ||
var migrationHook = require('./helper/migration-hook.js'); | ||
|
||
module.exports = function (internals, config, callback) { | ||
migrationHook(internals) | ||
.then(function () { | ||
var Migrator = require('../migrator.js'); | ||
var index = require('../../connect'); | ||
|
||
if (!internals.argv.count) { | ||
internals.argv.count = Number.MAX_VALUE; | ||
} | ||
index.connect({ | ||
config: config.getCurrent().settings, | ||
internals: internals | ||
}, Migrator, function (err, migrator) { | ||
if (!assert(err, callback)) return; | ||
|
||
if (internals.locTitle) { | ||
migrator.migrationsDir = path.resolve(internals.argv['migrations-dir'], | ||
internals.locTitle); | ||
} else { migrator.migrationsDir = path.resolve(internals.argv['migrations-dir']); } | ||
|
||
internals.migrationsDir = migrator.migrationsDir; | ||
|
||
migrator.driver.createMigrationsTable(function (err) { | ||
if (!assert(err, callback)) return; | ||
log.verbose('migration table created'); | ||
|
||
migrator.check(internals.argv, internals.onComplete.bind(this, | ||
migrator, internals, callback)); | ||
}); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var Code = require('code'); | ||
var Lab = require('lab'); | ||
var proxyquire = require('proxyquire').noPreserveCache(); | ||
var lab = (exports.lab = Lab.script()); | ||
|
||
lab.experiment('migrators', function () { | ||
lab.experiment('check', function () { | ||
lab.test('should return the migrations to be run', function (done) { | ||
var completedMigration = { | ||
name: '20180330020329-thisMigrationIsCompleted' | ||
}; | ||
var uncompletedMigration = { | ||
name: '20180330020330-thisMigrationIsNotCompleted' | ||
}; | ||
var Migrator = proxyquire('../lib/migrator.js', { | ||
'./migration': { | ||
loadFromFilesystem: (migrationsDir, internals, cb) => { | ||
return cb(null, [completedMigration, uncompletedMigration]); | ||
}, | ||
loadFromDatabase: (migrationsDir, driver, internals, cb) => { | ||
return cb(null, [completedMigration]); | ||
} | ||
} | ||
}); | ||
Migrator.prototype.check(null, function (err, res) { | ||
Code.expect(res.length).to.equal(1); | ||
Code.expect(res[0].name).to.equal(uncompletedMigration.name); | ||
done(err, res); | ||
}); | ||
}); | ||
}); | ||
}); |