Skip to content

capstone-project-alterra-9/knex-migrations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

knex-migration

Used for maintaining knex migration scripts on relational database.

Getting Started

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.

Migration

  1. Make sure you have already done with the above steps.
  2. List all migrations files with status.
$ knex migrate:list
  1. Run all migrations that have not yet been run.
$ knex migrate:latest
  1. Add a new migration script.
$ knex migrate:make migration_name
  1. Write your migration script to the newly created migration file in the migrations folder.

  2. Run the next, or the specified migration that has not yet been run.

$ knex migrate:up

# or

$ knex migrate:up 001_migration_name.js
  1. Undo the last, or the specified migration that was already run.
$ knex migrate:down

# or

$ knex migrate:down 001_migration_name.js

Seed

  1. Add a new seed script.
$ knex seed:make seed_name
  1. Write your seed script to the newly created migration file in the seeds folder.

  2. Seed files are executed in alphabetical order. Unlike migrations, every seed file will be executed when you run the command.

  3. Run all or the specified seed file.

$ knex seed:run

# or

$ knex seed:run --specific=seed-filename.js

Some References

For more information consult the web documentation or CLI help.

knex --help

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published