sequelize/cli — pull request #12 by sdepold (2014-06-22 18:02:54+00:00)
Title: sequelize model:create

Add `sequelize model:create` which generates a model and it corresponding migration file.

This task generates a model file and its respective migration.
It is necessary to specify the name of the new model as well as
the model's attributes.

The attributes can be specified as in the following (and semantically equal) examples:
```
sequelize model:create --name User --attributes first_name:string,last_name:string,bio:text
sequelize model:create --name User --attributes "first_name:string last_name:string bio:text"
sequelize model:create --name User --attributes "first_name:string, last_name:string, bio:text"
```

This command will generate a new migration and model definition:
```
// the model file
// located under models/user.js
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define('User', {
first_name: DataTypes.STRING,
last_name: DataTypes.STRING,
bio: DataTypes.TEXT
}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
})

return User
}
```
```
// the migration file
// located under migrations/20140622195935-create-user.js
module.exports = {
up: function(migration, DataTypes, done) {
migration
.createTable('Users', {
first_name: DataTypes.STRING
last_name: DataTypes.STRING
bio: DataTypes.TEXT
})
.complete(done)
},
down: function(migration, DataTypes, done) {
migration
.dropTable('Users')
.complete(done)
}
}
```

# Discussion area:
I wonder if the API is OK or if there would be a better syntax for the attributes.