Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 76 lines (67 sloc) 1.779 kB
#!/usr/bin/env node
var optimist = require('optimist');
var cli = require('../lib/cli.js');
var config = require('../lib/config.js');
function loadConfig() {
try {
config.load(argv.db);
config.setCurrent(argv.env);
} catch(e) {
console.error(e.message);
process.exit(1);
}
if(verbose) {
console.log("using config:", config.getCurrent());
}
}
var argv = optimist
.default({
verbose: false,
db: process.cwd() + '/database.json',
'migrations-dir': process.cwd() + '/migrations',
env: 'dev' })
.usage('Usage: db-migrate [up|down|create] migrationName [options]')
.alias('e', 'env')
.alias('m', 'migrations-dir')
.alias('v', 'verbose')
.alias('h', 'help')
.alias('h', '?')
.describe('env', 'The environment to run the migrations under (dev, test, prod).')
.describe('migrations-dir', 'The directory containing your migration files.')
.describe('db', 'Location of the database.json file.')
.describe('verbose', 'Verbose mode.')
.argv
if (argv.help || argv._.length == 0) {
optimist.showHelp();
process.exit(1);
}
global.verbose = argv.verbose;
var action = argv._.shift();
switch(action) {
case 'create':
if(argv._.length == 0) {
console.error("*** 'migrationName' is required.");
optimist.showHelp();
process.exit(1);
}
argv.title = argv._.shift();
cli.create(argv);
break;
case 'up':
case 'down':
loadConfig();
if(argv._.length > 0) {
argv.destination = argv._.shift();
}
if(action == 'up') {
cli.up(argv);
} else {
cli.down(argv);
}
break;
default:
console.error("*** invalid action, must be [up|down|create].");
optimist.showHelp();
process.exit(1);
break;
}
Jump to Line
Something went wrong with that request. Please try again.