I've recently started to experiment with Sequelize Migrations using sequelize-cli. I noticed that if the migration script throws an error (using a try-catch block), sequelize-cli still updates the SequelizeMeta table with the migration as if it was successful.
What is the best way to catch errors and prevent Sequelize from entering the migration into the SequelizeMeta table on 'up', and conversely, prevent removing the migration when the 'down' script fails?
Use a transaction to achieve rolling back all migration changes due to an exception like this:
Don't forget to indicate
transaction
in all Sequelize method calls.Keep in mind that not all RDBMS support structure changes rolling back.