Reputation: 12916
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.
Upvotes: 22
Views: 36766
Reputation: 11
If you want to run a single migration at a time, you can use --name, here's an exemple:
npx sequelize-cli db:migrate --name XXXXXXXXXXXXXX-create-single-table.js
With that, you can run just the migrations you actually want to run. Hope it helps!
Upvotes: 1
Reputation: 134
I think the question was already answered, but some people still getting confused. I will try to give a straight answer for this specific question:
npx sequelize-cli db:migrate --to 20170316142544-create-an-index.js
In this specific case there's no need to add the option --from
, because 20170316142544-create-an-index.js
is the next migration to be applied.
But if the question was:
I would like to only run the
20170421112638-do-some-refactor.js
Then you would have to use the option --from
to jump all the other migrations until the desired one. In this case:
npx sequelize-cli db:migrate --from 20170316142544-create-an-index.js --to 20170421112638-do-some-refactor.js
Upvotes: 7
Reputation: 61
You can simply change the sequence of files in the migrations folder. As the filename always starts with timestamp so in order to change the sequence of migrations you just need to update the timestamp accordingly by renaming the file.
20170316142544-create-an-index.js. just see which migration ran latest and add rename this migration timestamp with the timestamp just next to the one that executed. add some typos in other ones after it or move them out of the folder for a second and then migrate.
Upvotes: 1
Reputation: 1166
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
Upvotes: 23
Reputation: 438
I think you maked all models and afther that you're trying to run the migrations.
So, I found one solution, i don't know if this is good idea. Sequelize names the migration files with instant actual date. So ,if you change the first string of name for the other wanted file, e.i.
20190717191628-create-team.js
20190717191909-create-player.js
**for**
20190717191909-create-team.js
20190717191628-create-player.js
After that,order all files like you want , and run the db:migrate command.
Upvotes: 1
Reputation: 9933
The things is, Sequelize only executes those migrations which are not executed yet, Means which is pending.
It means when you run command sequelize:migrate it will only executes those who is still pending.
Upvotes: 2