7

I'm working on a migration using Sequelize. If the migration up method throws an error, the migration is not logged in the database as having completed. So, if I run db:migrate:undo, it instead runs down on the previous (and working) migration. As a result, I have a half executed migration where the schema for it remains in the database because the corresponding down method is never run by Sequelize. So, I need to either somehow force a single down method to run (which I'm not seeing an option for). Or, I need to manually clean up my database every time I run a failing migration, which can be a real pain for complicated migrations where I'm constantly going through trial and error. Is there an easier way to doing this?

Matt Molnar
  • 2,412
  • 3
  • 22
  • 28

4 Answers4

13
sequelize db:migrate:undo --name 20200409091823-example_table.js

Use this command to undo any particular migration

Foram Sojitra
  • 391
  • 9
  • 19
2

manually insert the migration into your migrations table so that sequelize will think it has completed.

To verify check the status of your migrations before and after you edit the table.

db:migrate:status

Everything listed as "up" is something that can go "down" and vice versa.

user1990962
  • 361
  • 1
  • 11
0

There is no way to do it as of now... There is an open issue for this in Sequelize cli repo

Eslam Yahya
  • 89
  • 1
  • 8
0

I tried something and it worked for me:

  • rename your migration file and make sure it comes first alphabetically (make it the first one in migration files)
  • comment code in the second migration file
  • run sequelize db:migrate

This will run only the first migration file.

Don't forget to uncomment the migration file you commented before

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
M.Shaltoot
  • 33
  • 7