Modern migration toolkit for knex.js
- 100% compatible with knex.js migrations cli
- can migrate upto and downto any migration
- able to run individual migrations
- quickly rollback recent migrations
- redo feature: rollback and migrate again for quick testing
- runs migrations in transactions
- friendly ui 🌹
npm install --save knex-migrate
You should also install knex
as it's a peer dependency of this package.
First, init project with knex init
, add migrations with knex migrate:make
, and then:
Usage
$ knex-migrate <command> [options]
Commands
pending Lists all pending migrations
list Lists all executed migrations
up Performs all pending migrations
down Rollbacks last migration
rollback Rollbacks last batch of migrations
redo Rollbacks last batch and performs all migrations
Options for "up" and "down":
--to, -t Migrate upto (downto) specific version
--from, -f Start migration from specific version
--only, -o Migrate only specific version
Global options:
--cwd Specify the working directory
--knexfile Specify the knexfile path ($cwd/knexfile.js)
--migrations Specify migrations path ($cwd/migrations)
--env Specify environment ($KNEX_ENV || $NODE_ENV || 'development')
--verbose Be more verbose
As a convenience, you can skip --to flag, and just provide migration name.
Examples
$ knex-migrate up # migrate everytings
$ knex-migrate up 20160905 # migrate upto given migration name
$ knex-migrate up --to 20160905 # the same as above
$ knex-migrate up --only 201609085 # migrate up single migration
$ knex-migrate down --to 0 # rollback all migrations
$ knex-migrate down # rollback single migration
$ knex-migrate rollback # rollback previous "up"
$ knex-migrate redo --verbose # rollback and migrate everything
- @marcbachmann for inspiration and starting point (knex-umzug and umzug-cli)
MIT