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

Commit 46f5caf9 by terraflubb

Migration environment set from command line args

Still defaults to 'development' if NODE_ENV isn't set so backwards compatibility is ensured.
1 parent b168e557
Showing with 9 additions and 3 deletions
......@@ -8,6 +8,7 @@ const path = require("path")
, _ = Sequelize.Utils._
var configPath = process.cwd() + '/config'
, environment = process.env.NODE_ENV || 'development'
, migrationsPath = process.cwd() + '/migrations'
, packageJsonPath = __dirname + '/../package.json'
, packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString())
......@@ -52,10 +53,9 @@ var createMigrationsFolder = function(force) {
var readConfig = function() {
try {
var config = JSON.parse(fs.readFileSync(configFile))
, env = process.env.NODE_ENV || 'development'
if (config[env]) {
config = config[env]
if (config[environment]) {
config = config[environment]
}
return config
......@@ -68,11 +68,17 @@ program
.version(packageJson.version)
.option('-i, --init', 'Initializes the project. Creates a config/config.json')
.option('-m, --migrate', 'Runs undone migrations')
.option('-e, --env <environment>', 'Specify the environment.')
.option('-u, --undo', 'Undo the last migration.')
.option('-f, --force', 'Forces the action to be done.')
.option('-c, --create-migration [migration-name]', 'Create a new migration skeleton file.')
.parse(process.argv)
if(typeof program.env === 'string') {
environment = program.env
}
console.log("Using environment '" + environment + "'.")
if(program.migrate) {
if(configFileExists) {
var config = readConfig()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!