A simple knex like CLI for neo4j migrations
$ npm i @letapp/knex-neo4j
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
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
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.
Once you have finished writing the migrations, you can update the database by running:
$ knex-neo4j migrate:latest
To rollback the last migration:
$ knex-neo4j migrate:rollback
View the current version for the migration:
$ knex-neo4j migrate:currentVersion
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
module.exports = {
connection: 'bolt://localhost:7687',
user: 'user',
password: 'password',
};
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
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',
}
MIT - see LICENSE