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.
To run the specific migration in Laravel, you need to use --path option with the php artisan migrate command. Let's take a simple example, we have '2019_12_04_131405_create_payments_table. php' migration in the database/migrations directory and we would like to run this migration.
To run a specific migration up or down, use db:migrate:up or db:migrate:down . The version number in the above commands is the numeric prefix in the migration's filename. For example, to migrate to the migration 20160515085959_add_name_to_users. rb , you would use 20160515085959 as the version number.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With