Skip to content

A simple knex-like migration cli for neo4j database.

License

Notifications You must be signed in to change notification settings

letapp/knex-neo4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

knex-neo4j CLI

A simple knex like CLI for neo4j migrations

Installation

$ npm i @letapp/knex-neo4j

Available commands

Use --help to see all available commands:

$ knex-neo4j --help

When a command is specified, use --help to see all available command options, e.g.:

$ knex-neo4j migrate:latest --help

init

Migrations use a config file (default knexneo4jfile.js), which specify various configuration settings for the module. To create a new config file, run the following:

$ knex-neo4j init

More details in the configuration section

migrate:make

Once you have a config file, you can use the migration tool to create migration files to the specified directory (default migrations/neo4j). Creating new migration files can be achieved by running:

$ knex-neo4j migrate:make migration_name

The migration file will be named yyyymmddhhmmss_migration_name.js and will contain the content like this:

exports.up = (run) => {
  return run(
    // query, params
  );
};

exports.down = (run) => {
  return run(
    // query, params
  );
};

Migration function accepts async function run, you can use async/await syntax to run a query or return run with specified query and params.

migrate:latest

Once you have finished writing the migrations, you can update the database by running:

$ knex-neo4j migrate:latest

migrate:rollback

To rollback the last migration:

$ knex-neo4j migrate:rollback

migrate:currentVersion

View the current version for the migration:

$ knex-neo4j migrate:currentVersion

Configuration file

A config file generally contains all of the configuration for your database. It can optionally provide different configuration for different environments and additional options for migrations. You may pass a --config option to any of the command line statements to specify an alternate path to your config file (default knexneo4jfile.js).

$ knex-neo4j init --config configs/config_name.js

Basic configuration:

module.exports = {
  connection: 'bolt://localhost:7687',
  user: 'user',
  password: 'password',
};

Environment configuration:

module.exports = {
  development: {
    connection: 'bolt://localhost:7687',
    user: 'user',
    password: 'password',
  },

  production: {
    connection: '',
    user: '',
    password: '',
  },
};

You can also pass the --env option or set NODE_ENV to any of the command line statements to select an alternative environment.

$ knex-neo4j migrate:latest --env production

# or

$ NODE_ENV=production knex-neo4j migrate:latest

Additional configurations

You can add additional fields to your config file:

  • directory - a relative path to the directory containing the migration files (default ./migrations/neo4j).
  • storageNode - the node label used for storing the migration state (default KNEX_NEO4J_MIGRATION)
{
  connection: '',
  user: '',
  password: '',
  directory: './path_to_migrations_dir',
  storageNode: 'MIGRATION_NODE_LABEL',
}

License

MIT - see LICENSE

About

A simple knex-like migration cli for neo4j database.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published