valtlfelipe / hapi-sequelizejs

A hapi.js plugin to connect with Sequelize ORM
MIT License
62 stars 17 forks source link

Running migrations #3

Closed iwasrobbed closed 7 years ago

iwasrobbed commented 7 years ago

Can you give a quick example of how I would run migrations generated by the CLI using this?

valtlfelipe commented 7 years ago

This plugin is just a connector between hapi.js and sequelize.js. Please refer to the sequelize.js docs on how to run migrations. Please have a look at: http://docs.sequelizejs.com/en/latest/docs/migrations/

iwasrobbed commented 7 years ago

For future reference, here's an example:

$ sequelize migration:create --name "addSomeGreatNewThing"

Then you'll add a migration and use the regular interface

'use strict';

module.exports = {
  up: function (queryInterface, Sequelize) {

    /*
     Add altering commands here.
     Return a promise to correctly handle asynchronicity.

     Example:
     return queryInterface.createTable('users', { id: Sequelize.INTEGER });
     */

      return queryInterface.addColumn(
          'MyTable',
          'comingSoon',
          {
              type: Sequelize.BOOLEAN,
              defaultValue: true
          }
      );
  },

  down: function (queryInterface, Sequelize) {
    /*
      Add reverting commands here.
      Return a promise to correctly handle asynchronicity.

      Example:
      return queryInterface.dropTable('users');
    */

      return queryInterface.removeColumn(
          'MyTable',
          'comingSoon'
      );
  }
};

Then you can run the normal commands:

$ sequelize db:migrate
$ sequelize db:migrate:undo
valtlfelipe commented 7 years ago

Thank you @iwasrobbed !