Run only the next migration file

Automatico picture Automatico · Apr 24, 2017 · Viewed 9.8k times · Source

Is it possible to run only the next migration file with the sequelize-cli?

I have been looking through the docs and help-section of the cli, and it does not appear to be such a feature.

For instance, I have the following when running the sequelize db:migrate:status command;

Loaded configuration file "config/config.js".
Using environment "development".
up   20170301090141-create-something.js
up   20170301133113-create-else.js
up   20170301133821-Update-some-stuff.js
up   20170301135339-create-some-model.js
up   20170307152706-update-some-stuff-two.js
down 20170316142544-create-an-index.js
down 20170421112638-do-some-refactor.js

I would like to only run the 20170316142544-create-an-index.js.

Of course, I can remove all the relevant files. Then I add each migration back one-by-one, running "all" migrations between each one. But this seems so barbaric.

Answer

Faheem picture Faheem · Feb 6, 2020

I came here from Google and was not able to find any options in doc. However, the CLI sequelize-cli db:migrate --help shows an option to select a range of migrations you want to run.

They are:

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

Apparently, you need to provide the exact filename not the migration name. (Found in source code)

TLDR:

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