I'd like to be able to rollback a specific knex
migration on the command line.
For example:
knex migrate:rollback('20161104101325')
Is this possible?
Rolling back the migration means running the code in the down method in the migration file, which destroys the whole fruits table and all the data in it. We could then adjust the line where the weight column is created by adding the call to notNullable() . We could finally run the migration again.
You can rollback your migration by using rake db:rollback with different options. The syntax will be different according to your requirements. where n is number of migrations to rollback, counting from latest migration. where xxxxx is the version number of the migration.
From the doc:
To undo the specified migration that was run
$ knex migrate:down 001_migration_name.js
To run the specified migration that has not yet been run
$ knex migrate:up 001_migration_name.js
To list both completed and pending migrations:
$ knex migrate:list
(to list and check)
(migrate:list
was released in 0.19.3! if not available update knex (npm i -g knex
))
Update: This answer is now out of date - the functionality was since implemented in knex as stated by mcating comment and by Mohamed in this answer
At this point of time this is not possible - you can find the discussion of this feature in this GitHub ticket: #666
You can use knex-migrate which is a migration toolkit for knex and supports the --only
flag for rollbacks.
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