# gremlin-migrate

> Runs gremlin-groovy scripts in-order to upgrade the DB schema

Latest version **1.0.8** (published 2021-08-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install gremlin-migrate
pnpm add gremlin-migrate
yarn add gremlin-migrate
bun add gremlin-migrate
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2021-08-27 |
| First published | 2016-12-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 133.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | John Stephenson |
| Maintainers | jfstephe |
| Keywords | gremlin, titan, janusgraph, database, graph, upgrade, migration, migrate |

## Links

- npm: https://www.npmjs.com/package/gremlin-migrate
- Repository: https://github.com/jfstephe/gremlin-migrate
- Homepage: https://github.com/jfstephe/gremlin-migrate#readme
- Issues: https://github.com/jfstephe/gremlin-migrate/issues
- npm.io page: https://npm.io/package/gremlin-migrate

## Dependencies (4)

- [bunyan](https://npm.io/package/bunyan.md) ^1.8.10
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [semver](https://npm.io/package/semver.md) ^5.3.0
- [gremlin](https://npm.io/package/gremlin.md) ^2.5.1

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 1.0.8 (latest) — 2021-08-27
- 1.0.7 — 2021-08-27
- 1.0.6 — 2017-10-09
- 1.0.5 — 2017-10-09
- 1.0.4 — 2017-09-18
- 1.0.3 — 2016-12-30
- 1.0.2 — 2016-12-29
- 1.0.1 — 2016-12-29
- 1.0.0 — 2016-12-29

## README

# gremlin-migrate
Runs gremlin-groovy scripts in-order to upgrade the DB schema

This library can be used to run a sequence of groovy scripts, which are submitted to [gremlin-javascript](https://github.com/jbmusso/gremlin-javascript), 
to perform changes on the target database. Most likely these will be schema changes.

The files are ordered based on [semver](https://github.com/npm/node-semver) naming conventions.

## Installation

```bash
npm install gremlin-migrate --save
```

## Usage
The library exports a function taking configuration parameters and returning an ES6 promise.

```typescript
import upgradeDbToLatest from 'gremlin-migrate';
...
upgradeDbToLatest(janusGraphDbAddress, portNumber, pathToUpgradeScriptDirectory).then(() => {
    console.log('SUCCESS!');
});
```

### Script library
If you want to use common functions across your groovy files, you can put them in a 'common.groovy' file in the update script directory. These will be available in all of the upgrade files.

## Example

### 0.0.1.groovy (in 'upgradeScripts' subdir)
```groovy
// I am an example of a comment!
graph.addVertex(label, 'person').property('name', 'john').iterate();
person2 = graph.addVertex(label, 'person');
// NOTE: Don't forget to add the '.next()' else the step won't necessarily take effect!
person2.property('name', 'john').next();
// DON'T put transactions in your upgrade scripts. The scripts are automatically wrapped in a transaction.
// graph.tx().commit();
```

### Example.ts

```typescript
import { createClient } from 'gremlin';
import upgradeDbToLatest from 'gremlin-migrate';
const client = createClient(8182, '192.168.99.100');

export default class Example {
  public test() {
    client.execute('g.V().hasLabel(\'person\').has(\'name\', \'john\')', (err, results) => {
      console.log('BEFORE UPGRADE: ' + JSON.stringify(results)); // []
      upgradeDbToLatest('192.168.99.100', 8182, __dirname + '/upgradeScripts/').then(() => {
        client.execute('g.V().hasLabel(\'person\').has(\'name\', \'john\')', (err, results) => {
          console.log('AFTER UPGRADE: ' + JSON.stringify(results)); // [ {vertex with person 'john'} ]
        });
      });
    });
  }
}
```


## Tests

The tests are run against a janus-graph/dynamoDb backend configuration to exercise the transaction locking. They spin up docker containers using [docker-compose](https://docs.docker.com/compose/install/) with an empty DB so you will need docker set up on your system.

Run 'docker-compose build' and wait until that finishes (this is a one-off step)

Run 'gulp build' to build the app.

Then run 'gulp test' to run the tests.

## To Publish

1. Build and test the app.
2. Run 'gulp export' to prepare for the release
3. Commit and push your changes up to github
4. npm publish!

## About
My specific use-case was for [flyway](https://flywaydb.org/)-like migrations for janus-graph, but I couldn't find a tool that did that.

## Contributions
Pull requests will be gratefully received. Please ensure you have a test around the change/improvement you are proposing.

---
_Source: https://npm.io/package/gremlin-migrate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
