npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

neo4j-data-migrations

v1.2.2

Published

Easy data migration system for neo4j graphs.

Downloads

129

Readme

neo4j-data-migrations

NodeJS library to allow easy data migrations for neo4j graph databases.

Inspired by (https://south.readthedocs.io/en/latest/)

Requirements

Neo4j version 3.

Look at version 2.x for usage with neo4j version 4.

Installation

Install package:

npm install neo4j-data-migrations

Setup reference migration directory structure:

neo4j-data-migrate --setup

This will add a datamigrations directory to the current working directory. Inside, a sample app directory is added with an example migration script.

A connection is made to the neo4j database by means of the driver from the neo4j-driver. The configuration is stored in datamigrations/configuration.js.

Refer to (https://neo4j.com/docs/api/javascript-driver/current/function/index.html#static-function-driver) for configuration of the driver.

Usage

Command-line

The command-line tool is used to control the migration of the system forwards or backwards through the series of migrations for any given app.

The most common use is:

neo4j-data-migrate myapp

This will migrate the app myapp forwards through all the migrations. If you want to migrate all the apps at once, run:

neo4j-data-migrate

This has the same effect as calling the first example for every app, and will deal with dependencies properly.

You can also just give prefixes of migrations:

neo4j-data-migrate myapp 0002

Note that, if the system has already migrated past the specified migration, it will roll back to it instead. If you want to migrate all the way back, specify the special migration name zero:

neo4j-data-migrate myapp zero

Options

The following options are available to change behaviour of the migration tool:

  • -d [path] Path to the migrations directory.

Adding migrations

If you want to add a data migration script, add a .js file with the appropriate prefix in the datamigrations and app (sub-)directory. You need to keep track of the increment of the prefix to ensure correct migration order.

Migration format

Each migration file should export an anonymous object exposing three properties:

  • name {String} Verbose description of the migration
  • forward {async Function} Forward migration script, requires a driver parameter.
  • backward {async Function} Backwards migration script, requires a driver parameter.

The driver parameter is used to handle neo4j migrations.

Example migration file:

module.exports = {
  name: 'Add users',
  forward: async (driver) => {
    driver.session();
    await session.run(
      'CREATE (user:User {name: {name}, age: {age}})',
      { name: 'Username', age: 30 },
    );
    session.close();
  },
  backward: async (driver) => {
    driver.session();
    await session.run(
      'MATCH (user:User {name: {name}}) DELETE user',
      { name: 'Username' },
    );
    session.close();
  },
};

Migration metadata storage

The library keeps track of the migration schema in neo4j using nodes labeled __dm. Nodes are automatically created and removed by the library.

Inclusion in continuous integration and deployment

You can include the neo4j-data-migrate command in the deployment script of your application. Ensure it is run before the rest of your application is started.

API usage

It is possible to programmaticaly use the migration library by means of dependency injection. An example:

import Migrate from 'neo4j-data-migration';

Migrate.configure(__dirname);
Migrate.all(); // Migrate all apps at once.
Migrate.app('myapp', '0002') // Migrate myapp to 0002.
Migrate.app('myapp, 'zero') // Migrate myapp to zero.
Migrate.close();

License

MIT

Author

Remco Hendriks, ABN AMRO Bank 2019.