How to run a specific migration using sequelize-cli?

Lots of birds are flying in a greyscale photo. This photo is to illustrate migration.
Lots of birds are flying. Photo by Somya Dinkar from Pexels

Sequelize-cli makes it very easy to create and run migrations. It also keeps track of migrations you have run so only new migrations are processed when you run the migrations again.

But sometimes, for any reason, you may want to run a specific migration. How do you do that?

I had the same case and wanted to run a specific migration but could not find anything on the documentation.

So I ran the following command to get some help.

sequelize-cli db:migrate --help

Turns out I can pass the some arguments to create a range of migrations I want to run.

--to    // Migration name to run migrations until
--from  // Migration name to start migrations from (excluding)

I tried passing the arguments but it did not work so I decided to see the source code. Apparently, it needs the filename instead of the migration name. I ran again and was successful.

npx sequelize-cli db:migrate --from will-not-be-included.js --to filename.js

I have also posted this on a Stack overflow question here.

Default image
Muhammad Faheem Akhtar
I am a Software Engineer
Articles: 2

Leave a Reply