How to Add, Delete new Columns in Sequelize CLI

后端 未结 7 1894
刺人心
刺人心 2020-12-07 16:43

I\'ve just started using Sequelize and Sequelize CLI

Since it\'s a development time, there are a frequent addition and deletion of columns. What the best the method

7条回答
  •  青春惊慌失措
    2020-12-07 17:21

    If you are working in vscode, you can add type definition in the migration file. which helps to identify all the methods QueryInterface and sequelize provide.

     module.exports = {
    /**
       * @typedef {import('sequelize').Sequelize} Sequelize
       * @typedef {import('sequelize').QueryInterface} QueryInterface
       */
    
      /**
       * @param {QueryInterface} queryInterface
       * @param {Sequelize} Sequelize
       * @returns
       */
      up: function(queryInterface, Sequelize) {
        // logic for transforming into the new state
        return queryInterface.addColumn(
          'Todo',
          'completed',
         Sequelize.BOOLEAN
        );
    
      },
    
      down: function(queryInterface, Sequelize) {
        // logic for reverting the changes
        return queryInterface.removeColumn(
          'Todo',
          'completed'
        );
      }
    }
    

    Which will provide intellisense like below

提交回复
热议问题