Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abnamrocoesd/neo4j-data-migrations
NodeJS library to allow easy data migrations for Neo4j graph databases.
https://github.com/abnamrocoesd/neo4j-data-migrations
javascript migrations neo4j
Last synced: about 20 hours ago
JSON representation
NodeJS library to allow easy data migrations for Neo4j graph databases.
- Host: GitHub
- URL: https://github.com/abnamrocoesd/neo4j-data-migrations
- Owner: abnamrocoesd
- License: mit
- Created: 2019-04-25T11:33:02.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-13T21:09:26.000Z (almost 2 years ago)
- Last Synced: 2024-12-16T00:47:50.359Z (29 days ago)
- Topics: javascript, migrations, neo4j
- Language: JavaScript
- Size: 247 KB
- Stars: 17
- Watchers: 7
- Forks: 3
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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 4.
Look at version 1.x for usage with neo4j version 3.
# 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, --dir [path]` Path to the migrations directory.
- `-g, --databasse [name]` Name of database to run migrations for.# 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. It accepts a `database` parameter to select a database.
Example migration file:
```
module.exports = {
name: 'Add users',
forward: async (driver) => {
driver.session({
database: 'movies',
});
await session.run(
'CREATE (user:User {name: {name}, age: {age}})',
{ name: 'Username', age: 30 },
);
session.close();
},
backward: async (driver) => {
driver.session({
database: 'movies',
});
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 programmatically use the migration library by means of dependency injection. An example:
```
import Migrate from 'neo4j-data-migrations';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.