25

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?

steel
  • 11,883
  • 7
  • 72
  • 109

2 Answers2

26

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))

Mohamed Allal
  • 17,920
  • 5
  • 94
  • 97
9

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.

kyrisu
  • 4,541
  • 10
  • 43
  • 66
  • 2
    A knex migrate:down capability was added around May 28, 2019. See https://github.com/knex/knex/issues/666. – mcating Oct 25 '19 at 00:28