不要怂,就是干,撸起袖子干!

Commit 121aefa1 by Sascha Depold

Merge branch 'master' of https://github.com/codeinvain/sequelize into codeinvain-master

2 parents eb034333 8cc1fbfb
......@@ -16,6 +16,18 @@ var configuration = {
migrationsPath: process.cwd() + '/migrations'
}
var loadDefaultOptions = function(path){
try{
options = require(process.cwd()+'/'+path);
for (var key in options){
program[key] = options[key];
}
}catch(e){
console.log(e);
throw new Error('Error reading "' + path + '".')
}
}
var configFileExists = function() {
return fs.existsSync(configuration.configFile)
}
......@@ -82,12 +94,26 @@ var createMigrationsFolder = function(force) {
}
try {
fs.mkdirSync(configuration.migrationsPath)
mkdirp(configuration.migrationsPath);
console.log('Successfully created migrations folder at "' + configuration.migrationsPath + '".')
} catch(e) {
}
}
var mkdirp = function (path, root) {
var dirs = path.split('/'), dir = dirs.shift(), root = (root||'')+dir+'/';
try { fs.mkdirSync(root); }
catch (e) {
//dir wasn't made, something went wrong
if(!fs.statSync(root).isDirectory()) throw new Error(e);
}
return !dirs.length||mkdirp(dirs.join('/'), root);
}
var parseDbUrl = function(urlString) {
var urlParts,
config = {};
......@@ -155,11 +181,17 @@ program
.option('-u, --undo', 'Undo the last migration.')
.option('-f, --force', 'Forces the action to be done.')
.option('-c, --create-migration [migration-name]', 'Creates a new migration.')
.option('-p, --migrations-path <migration-path>', 'migration directory path.')
.option('-U, --url <url>', 'Database url. An alternative to a config file')
.option('-o,--cli-options <options_file>', 'Specifies lib options from file.')
.option('--config <config_file>', 'Specifies alternate config file.')
.option('--coffee', 'Consider coffee script files as migration source.')
.parse(process.argv)
if(typeof program.cliOptions === 'string') {
loadDefaultOptions(program.cliOptions);
}
if(typeof program.config === 'string') {
if (isRelativePath(program.config)) {
configuration.configFile = path.join(process.cwd(), program.config);
......@@ -168,6 +200,10 @@ if(typeof program.config === 'string') {
}
}
if(typeof program.migrationsPath=== 'string') {
configuration.migrationsPath = program.migrationsPath;
}
if(typeof program.env === 'string') {
configuration.environment = program.env
}
......@@ -307,3 +343,4 @@ if (program.migrate || program.undo) {
} else {
console.log('No action specified. Try "sequelize --help" for usage information.')
}
{
"configFile": "./config/database.json",
"migrationsPath": "./db/migrate"
}
......@@ -67,6 +67,17 @@ if (os.type().toLowerCase().indexOf('windows') === -1) {
})
})(['config', 'migrations'])
it("creates a custom migrations folder", function(done) {
exec("rm -rf ./*", { cwd: __dirname + '/tmp' }, function() {
exec("../../bin/sequelize --init -p ./db/migrate", { cwd: __dirname + '/tmp' }, function() {
exec("ls -ila", { cwd: __dirname + '/tmp' }, function(err, stdout) {
expect(stdout).to.include('db')
done()
})
})
})
})
it("creates a config.json file", function(done) {
exec("rm -rf ./*", { cwd: __dirname + '/tmp' }, function() {
exec("../../bin/sequelize --init", { cwd: __dirname + '/tmp' }, function() {
......@@ -93,6 +104,8 @@ if (os.type().toLowerCase().indexOf('windows') === -1) {
})
})
})
})
})
})(['--init', '-i'])
......@@ -435,6 +448,25 @@ if (os.type().toLowerCase().indexOf('windows') === -1) {
})
})
})(['--url', '-U'])
;(function(flags) {
flags.forEach(function(flag) {
describe(flag, function() {
it("using options file instead of cli switches", function(done) {
exec("rm -rf ./*", { cwd: __dirname + '/tmp' }, function() {
exec( "../../bin/sequelize --init "+flag+" ../../config/options.json" , { cwd: __dirname + '/tmp' }, function() {
exec("ls -ila", { cwd: __dirname + '/tmp' }, function(err, stdout) {
expect(stdout).to.include('db')
done()
})
})
})
})
});
})
})(['--cli-options', '-o'])
})
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!