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

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