Used for maintaining knex migration scripts on relational database.
Make sure you have knex
installed globally, so you can call the knex cli command.
$ npm i knex -g
Alternatively you can call knex cli command by accessing the binary in node_modules
after installing it locally.
$ ./node_modules/knex/bin/cli.js -V
Install modules.
$ npm i
Set the environment variables, the example can be found at .env.example
file.
- Make sure you have already done with the above steps.
- List all migrations files with status.
$ knex migrate:list
- Run all migrations that have not yet been run.
$ knex migrate:latest
- Add a new migration script.
$ knex migrate:make migration_name
-
Write your migration script to the newly created migration file in the
migrations
folder. -
Run the next, or the specified migration that has not yet been run.
$ knex migrate:up
# or
$ knex migrate:up 001_migration_name.js
- Undo the last, or the specified migration that was already run.
$ knex migrate:down
# or
$ knex migrate:down 001_migration_name.js
- Add a new seed script.
$ knex seed:make seed_name
-
Write your seed script to the newly created migration file in the
seeds
folder. -
Seed files are executed in alphabetical order. Unlike migrations, every seed file will be executed when you run the command.
-
Run all or the specified seed file.
$ knex seed:run
# or
$ knex seed:run --specific=seed-filename.js
For more information consult the web documentation or CLI help.
knex --help