How to run Sequelize down migration for single file
Asked Answered
H

4

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?

Hysteresis answered 26/6, 2018 at 17:58 Comment(0)
M
13
sequelize db:migrate:undo --name 20200409091823-example_table.js

Use this command to undo any particular migration

Misogynist answered 26/6, 2020 at 4:23 Comment(0)
P
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.

Piffle answered 6/11, 2019 at 20:28 Comment(0)
R
0

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

Repugn answered 4/11, 2018 at 9:45 Comment(0)
S
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

Schinica answered 4/7, 2020 at 18:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.