27

If we created 2 new migration scripts and ran

sequelize-cli db:migrate

, both migration scripts will run.

Both migrations are also reverted when we ran once the command

sequelize-cli db:migrate:undo

Question: Can we undo only the latest of the 2 migrations?

Using node 13.7.0, sequelize 5.21.3, sequelize-cli 5.5.1, PostgreSQL 11.2.

Nyxynyx
  • 61,411
  • 155
  • 482
  • 830

1 Answers1

53

Use name option:

db:migrate:undo --name 20180704124934-create-branch.js
Buszmen
  • 1,978
  • 18
  • 25
  • This worked! Although I must admit, I'm much more used to the idea of "stepping" backwards through a migration. I guess using the name makes it more explicit to what point you're exactly migrating back to - just a bit non-standard for the frameworks I've used. – Aaron Krauss Jun 09 '21 at 14:21
  • 1
    Thanks man. it works. Perhaps if sequelize cli is installed globally, a person should run the command from terminal like this `npx sequelize-cli db:migrate:undo --name db:migrate:undo --name 20180704124934-create-branch.js` – Niyongabo Eric Oct 13 '21 at 03:41
  • 1
    `npx sequelize-cli db:migrate :undo --name 20230406073112-create-history ` Unknown arguments: name, :undo `"sequelize": "^6.6.5", "sequelize-cli": "^6.2.0",` – Yogi Arif Widodo Apr 05 '23 at 23:56