-
-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tobias Gurtzick <[email protected]>
- Loading branch information
Showing
5 changed files
with
180 additions
and
0 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,52 @@ | ||
var path = require('path'); | ||
var log = require('db-migrate-shared').log; | ||
var migrationHook = require('./helper/migration-hook.js'); | ||
|
||
async function prepare (internals, config) { | ||
try { | ||
await migrationHook(internals); | ||
var Migrator = require('../walker.js'); | ||
var index = require('../../connect'); | ||
|
||
if (!internals.argv.count) { | ||
internals.argv.count = Number.MAX_VALUE; | ||
} | ||
const migrator = await index.connect( | ||
{ | ||
config: config.getCurrent().settings, | ||
internals: internals, | ||
prefix: 'migration' | ||
}, | ||
Migrator | ||
); | ||
|
||
if (internals.locTitle) { | ||
migrator.directory = path.resolve( | ||
internals.argv['migrations-dir'], | ||
internals.locTitle | ||
); | ||
} else { | ||
migrator.directory = path.resolve(internals.argv['migrations-dir']); | ||
} | ||
|
||
internals.migrationsDir = migrator.directory; | ||
|
||
await migrator.createMigrationsTable(); | ||
log.verbose('migration table created'); | ||
|
||
return migrator; | ||
} catch (err) { | ||
throw err; | ||
} | ||
} | ||
|
||
module.exports = async function (internals, config) { | ||
const migrator = await prepare(internals, config); | ||
|
||
try { | ||
const res = await migrator.fix(internals.argv); | ||
return internals.onComplete(migrator, internals, null, res); | ||
} catch (err) { | ||
return internals.onComplete(migrator, internals, err); | ||
} | ||
}; |
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