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

Commit 2fece681 by Sascha Depold

Merge branch 'terraflubb-make_binary_verbose'

2 parents 48eba5f5 2514c2de
......@@ -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())
......@@ -50,34 +51,52 @@ var createMigrationsFolder = function(force) {
}
var readConfig = function() {
var config
try {
var config = JSON.parse(fs.readFileSync(configFile))
, env = process.env.NODE_ENV || 'development'
config = fs.readFileSync(configFile)
} catch(e) {
throw new Error('Error reading "config/config.json".')
}
if (config[env]) {
config = config[env]
}
try {
config = JSON.parse(config)
} catch (e) {
throw new Error('Error parsing "config/config.json" as JSON.')
}
return config
} catch(e) {
throw new Error('The config.json is not available or contains invalid JSON.')
if (config[environment]) {
config = config[environment]
}
return config
}
program
.version(packageJson.version)
.option('-i, --init', 'Initializes the project. Creates a config/config.json')
.option('-m, --migrate', 'Runs undone migrations')
.option('-i, --init', 'Initializes the project.')
.option('-e, --env <environment>', 'Specify the environment.')
.option('-m, --migrate', 'Run pending migrations.')
.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.')
.option('-c, --create-migration [migration-name]', 'Creates a new migration.')
.parse(process.argv)
if(typeof program.env === 'string') {
environment = program.env
}
console.log("Using environment '" + environment + "'.")
if(program.migrate) {
if(configFileExists) {
var config = readConfig()
var config
, options = {}
try {
config = readConfig()
} catch(e) {
console.log(e.message)
process.exit(1)
}
_.each(config, function(value, key) {
if(['database', 'username', 'password'].indexOf(key) == -1) {
options[key] = value
......@@ -104,7 +123,8 @@ if(program.migrate) {
sequelize.migrate()
}
} else {
throw new Error('Please add a configuration file under config/config.json. You might run "sequelize --init".')
console.log('Cannot find "config/config.json". Have you run "sequelize --init"?')
process.exit(1)
}
} else if(program.init) {
if(!configFileExists || !!program.force) {
......@@ -129,9 +149,10 @@ if(program.migrate) {
}
})
console.log('Successfully created config.json')
console.log('Created "config/config.json"')
} else {
console.log('A config.json already exists. Run "sequelize --init --force" to overwrite it.')
console.log('"config/config.json" already exists. Run "sequelize --init --force" to overwrite.')
process.exit(1)
}
createMigrationsFolder(program.force)
......@@ -140,21 +161,23 @@ if(program.migrate) {
var migrationName = [
moment().format('YYYYMMDDHHmmss'),
(typeof program.createMigration == 'string') ? program.createMigration : 'unnamed-migration'
(typeof program.createMigration === 'string') ? program.createMigration : 'unnamed-migration'
].join('-') + '.js'
var migrationContent = [
"module.exports = {",
" up: function(migration, DataTypes, done) {",
" // add altering commands here, calling 'done' when finished",
" done()",
" },",
" down: function(migration, DataTypes, done) {",
" // add reverting commands here, calling 'done' when finished",
" done()",
" }",
"}"
].join('\n')
fs.writeFileSync(migrationsPath + '/' + migrationName, migrationContent)
} else {
console.log('Please define any params!')
console.log('Try "sequelize --help" for usage information.')
}
......@@ -11,6 +11,7 @@
- [FEATURE] Support for bulk insert (`<DAOFactory>.bulkCreate()`, update (`<DAOFactory>.update()`) and delete (`<DAOFactory>.destroy()`) [#569](https://github.com/sequelize/sequelize/pull/569). thanks to optilude
- [FEATURE] Add an extra `queryOptions` parameter to `DAOFactory.find` and `DAOFactory.findAll`. This allows a user to specify `{ raw: true }`, meaning that the raw result should be returned, instead of built DAOs. Usefull for queries returning large datasets, see [#611](https://github.com/sequelize/sequelize/pull/611) janmeier
- [FEATURE] Added convenient data types. [#616](https://github.com/sequelize/sequelize/pull/616). Thanks to Costent
- [FEATURE] Binary is more verbose now. [#612](https://github.com/sequelize/sequelize/pull/612). Thanks to terraflubb
# v1.6.0 #
- [DEPENDENCIES] upgrade mysql to alpha7. You *MUST* use this version or newer for DATETIMEs to work
......
......@@ -53,16 +53,26 @@ module.exports = (function() {
migrations.reverse()
}
if (migrations.length === 0) {
self.options.logging("There are no pending migrations.")
} else {
self.options.logging("Running migrations...")
}
migrations.forEach(function(migration) {
var migrationTime
chainer.add(migration, 'execute', [options], {
before: function(migration) {
if (self.options.logging !== false) {
self.options.logging('Executing migration: ' + migration.filename)
self.options.logging(migration.filename)
}
migrationTime = process.hrtime()
},
after: function(migration) {
migrationTime = process.hrtime(migrationTime)
migrationTime = Math.round( (migrationTime[0] * 1000) + (migrationTime[1] / 1000000));
if (self.options.logging !== false) {
self.options.logging('Executed migration: ' + migration.filename)
self.options.logging('Completed in ' + migrationTime + 'ms')
}
},
success: function(migration, callback) {
......
......@@ -14,8 +14,8 @@ describe(Helpers.getTestDialectTeaser("Migrator"), function() {
before(function(done) {
this.init = function(options, callback) {
options = Helpers.Sequelize.Utils._.extend({
path: __dirname + '/assets/migrations',
logging: false
path: __dirname + '/assets/migrations',
logging: function(){}
}, options || {})
var migrator = new Migrator(this.sequelize, options)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!