title: Node Sequelize migrations/models is it possible to share the same code?
body: <p>I'm new at Sequelize so be patient.</p>
  
  <p>I started up a new project using Sequelize
  and migrations so I've got like this:</p>
  
  <h2>migrations/20150210104840-create-my-user.js:</h2>
  
  <pre><code>"use strict";
  module.exports = {
    up: function(migration, DataTypes, done) {
      migration.createTable("MyUsers", {
        id: {
          allowNull: false,
          autoIncrement: true,
          primaryKey: true,
          type: DataTypes.INTEGER
        },
        first_name: {
          type: DataTypes.STRING
        },
        last_name: {
          type: DataTypes.STRING
        },
        bio: {
          type: DataTypes.TEXT
        },
        createdAt: {
          allowNull: false,
          type: DataTypes.DATE
        },
        updatedAt: {
          allowNull: false,
          type: DataTypes.DATE
        }
      }).done(done);
    },
    down: function(migration, DataTypes, done) {
      migration.dropTable("MyUsers").done(done);
    }
  };
  </code></pre>
  
  <h2>models/myuser.js:</h2>
  
  <pre><code>"use strict";
  module.exports = function(sequelize, DataTypes) {
    var MyUser = sequelize.define("MyUser", {
      first_name: DataTypes.STRING,
      last_name: DataTypes.STRING,
      bio: DataTypes.TEXT
    }, {
      classMethods: {
        associate: function(models) {
          // associations can be defined here
        }
      }
    });
    return MyUser;
  };
  </code></pre>
  
  <p>as you can see the table definition
  is both on the migration and the model file.</p>
  
  <p>I'm wondering if there is a way to share
  the code ?</p>
  
  <p>I mean I don't like to have logic in two files
  if a field change I've to update twice.</p>
  
  <h2>UPDATE</h2>
  
  <p>following the Yan Foto example below
  a different way may be cleaner.</p>
  
  <h2>schemas/users</h2>
  
  <pre><code>'use strict';
  
  module.exports = {
      name: 'users',
      definition : function(DataTypes)  {
          return {
              id: {
                  type: DataTypes.INTEGER,
                  autoIncrement: true,
                  primaryKey: true
              },
              firstname: {
                  type:DataTypes.STRING
              },
              lastname: {
                  type:DataTypes.STRING
              },
              email: {
                  type: DataTypes.STRING,
                  unique: true
              },
              username: {
                  type:DataTypes.STRING,
                  unique: true
              }
          };
      }
  };
  </code></pre>
  
  <h2>models/users</h2>
  
  <pre class="lang-js prettyprint-override"><code>'use strict';
  
  var Schema = require('../schemas/users');
  
  module.exports = function(sequelize, DataTypes) {
      return sequelize.define(
          Schema.name,
          Schema.definition(DataTypes),
          {
              freezeTableName: true ,
                  instanceMethods: {
                  countTasks: function() {
                          // how to implement this method ?
                  }
                  }
          }
      );
  };
  </code></pre>
  
  <h2>migrations/20150720184716-users.js</h2>
  
  <pre><code>'use strict';
  
      var Schema = require('../schemas/users');
  
      module.exports = {
  
          up: function (queryInterface, Sequelize) {
                  return queryInterface.createTable(
                  Schema.name,
                  Schema.definition(Sequelize)
                  );
          },
  
          down: function (queryInterface, Sequelize) {
              return queryInterface.dropTable(Schema.name);
          }
  
      };
  </code></pre>