Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save apjyotirmay/66a568f66bda5fbdb36524d253b7b7b1 to your computer and use it in GitHub Desktop.
Save apjyotirmay/66a568f66bda5fbdb36524d253b7b7b1 to your computer and use it in GitHub Desktop.
Sequelize migration add/drop multiple columns (transacting)
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((t) => {
return Promise.all([
queryInterface.addColumn('table_name', 'column_name1', {
type: Sequelize.STRING
}, { transaction: t }),
queryInterface.addColumn('table_name', 'column_name2', {
type: Sequelize.STRING,
}, { transaction: t })
])
})
},
down: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((t) => {
return Promise.all([
queryInterface.removeColumn('table_name', 'column_name1', { transaction: t }),
queryInterface.removeColumn('table_name', 'column_name2', { transaction: t })
])
})
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment