Morpheus is database migration tool for Neo4j written in Typescript.

Related tags

Database morpheus
Overview

build-deploy Coverage Status a

Morpheus

Morpheus is a database migration tool for Neo4j written in Typescript.

Morpheus is a modern, open-source, database migration tool for Neo4j. It is designed to be a simple, intuitive tool for database migrations. It is inspired by Michael Simons tool for Java.

This project has been tested with Neo4j 4.4.4

Installation

Install the latest version of Morpheus:

npm install morpheus4j

Add a script to your project's package.json file:

"scripts": {
  "morpheus": "morpheus"
}

Usage

Create Migrations

You can create migrations using the morpheus command or manually.

For the first, just issue the command:

npm run morpheus create <migration_name>

Migrations will be created under the neo4j/migrations directory. Each migration will be a Cypher file with the name V1_0_0_ .cypher .

Or you can create/add the migration manually as long as it follows the naming convention as stated in the Michael's tool.

Initial Configuration

To run migrations, you need to configure Morpheus. To do so, create a .morpheus.json file in your project root directory and create a neo4j/migrations directory as well.

Or, you can use the init command:

npm run morpheus init

If you don't want to use a morpheus.json file, you can also use ENV variables as follows:

NEO4J_SCHEME=neo4j
NEO4J_HOST=localhost
NEO4J_PORT=7687
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=neo4j

Run Migrations

You can run migrations by running the following command:

npm run morpheus migrate

This will run all migrations in the neo4j/migrations directory.

How it works

The approach is simple. Morpheus will read all migrations in the neo4j/migrations directory and execute them in order.

For each migration, Morpheus will create a transaction and execute the migration. Thus a migration may contain multiple Cypher statements (each statement must end with ;).

Once a migration file is executed, Morpheus will keep track of the migration and will not execute em again.

Existing migration files that have already been executed can not be modified since they are stored in a database with their corresponding checksum (crc32).

If you want to revert a migration, create a new migration and revert the changes.

How does neo4j keep track of the migrations?

You can take a look at schema and explanation on Michael's README there's a neat graph that shows the migration chain.

Comments
  • Error when using lib with jest e2e tests

    Error when using lib with jest e2e tests

    Me again :)

    I m just trying to implement e2e tests and I run into this error :

     FAIL  test/app.e2e-spec.ts
      ● Test suite failed to run
    
        Cannot find module 'morpheus4j/nest' from '../src/app.module.ts'
    
        Require stack:
          /{path}/project-name/src/app.module.ts
          app.e2e-spec.ts
    
          2 | import { AppController } from './app.controller';
          3 | import { AppService } from './app.service';
        > 4 | import { MorpheusModule } from 'morpheus4j/nest';
            | ^
    

    Do you have any idea where it can come from ? I can provide a repo with this error reproducted, or just do :

    nest new project-test
    cd project-test
    npm install morpheus4j
    # set MorpheusModule module
    npm run test:e2e
    
    opened by maximeSurmontGH 5
  • Support Write and Schema modification

    Support Write and Schema modification

    First, thank for the lib :)

    When I am trying to run this script, mixing Write and Schema modifications :

    // neo4j/migrations/V1_0_0_first migration.cypher
    CREATE CONSTRAINT username_is_uniq IF NOT EXISTS FOR (user:User) REQUIRE user.username IS UNIQUE;
    CREATE (u:User {username:"user 01",id:"randomUUID()",createdAt:"localdatetime()"});
    

    It returns this error :

    Tried to execute Write query after executing Schema modification
    

    It seems to come from the prepareAndMigrateFile function, using the same transaction for each statement. I tried to use create a new transaction for each statement and it worked well.

    opened by maximeSurmontGH 5
  • How do you create migrations in nestjs?

    How do you create migrations in nestjs?

    Hey, First of, thanks for the tool. I have followed the instructions and created the morpheus config in forRoorAsync. Then my Nest app starts and tries to run migrations, which is expected. It also creates the __Neo4jMigration node of version BASELINE which is also expected. However, I can't create migrations with npm run morpheus init because it says that there is no .morpheus.json but I don't need .morpheus.json because I already have my config in main.ts. Also, if I try to create the migration manually in src/neo4j/migrations such as src/neo4j/migrations/V1_0_0__test.cypher it still says "Database up to date" when starting without performing the migrations. I ve gone through the code in the repo and I still seem unable to do it. Any advices?

    bug question 
    opened by KMV-7 2
  • refactor: Make compatible with neo4j-migrations.

    refactor: Make compatible with neo4j-migrations.

    In essence, the whole batch of changes included:

    • Somewhat standardized migrations name (V1_2_3__name.cypher)
    • Replaces id with version in the migration nodes
    • Do a path matching instead of <= id
    • Allows for arbitrary named verions
    • Uses an actual date in the time of migrations
    • Recording of the duration a single migration took
    • Use the same checksum algorithm as neo4j-migrations

    I locally ensured that morpheues can read neo4j-migrations and vice versa:

    image

    released 
    opened by michael-simons 2
  • feat!: release

    feat!: release

    Be aware: these changes will BREAK Morpheus version 1.

    opened by marianozunino 0
  • chore: release

    chore: release

    Be aware: these changes will BREAK Morpheus version 1.

    released 
    opened by marianozunino 0
  • Make compatible with neo4j-migrations.

    Make compatible with neo4j-migrations.

    This changes a couple of things and I can understand if you don't want this. Also, I haven't run the tests, I'm happy that I made npm and typescript work. I was able to migrate things with your tools and verify with mine and vice versa. Key point here is using the same hashing as well as not using numeric version ids. Also, I fixed the date (should be a real date) Also, I added the duration.

    I think both of our projects would benefit if interoperable. In mine, I would need to adapt to slightly different Cypher file names. However, I do thing the "VID__name.cypher" has a well established tradition inside database refactoring.

    If you don't want it as a whole, pick what you like :)

    • Allows for migrations having the naming V1_2_3__name.cypher
    • Replaces „id“ with „version“ in the migration nodes
    • Do a path matching instead of <= id
    • Allows for arbitrary named verions
    • Uses an actual date in the time of migrations
    • records he migrations
    • uses crc32 hashing of the files
    opened by michael-simons 0
Releases(v2.4.0)
Owner
Mariano Zunino
Mariano Zunino
🔥 Dreamy-db - A Powerful database for storing, accessing, and managing multiple database.

Dreamy-db About Dreamy-db - A Powerful database for storing, accessing, and managing multiple databases. A powerful node.js module that allows you to

Dreamy Developer 24 Dec 22, 2022
DolphinDB JavaScript API is a JavaScript library that encapsulates the ability to operate the DolphinDB database, such as: connecting to the database, executing scripts, calling functions, uploading variables, etc.

DolphinDB JavaScript API English | 中文 Overview DolphinDB JavaScript API is a JavaScript library that encapsulates the ability to operate the DolphinDB

DolphinDB 6 Dec 12, 2022
Lovefield is a relational database for web apps. Written in JavaScript, works cross-browser. Provides SQL-like APIs that are fast, safe, and easy to use.

Lovefield Lovefield is a relational database written in pure JavaScript. It provides SQL-like syntax and works cross-browser (currently supporting Chr

Google 6.8k Jan 3, 2023
The Blog system developed by nest.js based on node.js and the database orm used typeorm, the development language used TypeScript

考拉的 Nest 实战学习系列 readme 中有很多要说的,今天刚开源还没来及更新,晚些慢慢写,其实本人最近半年多没怎么写后端代码,主要在做低代码和中台么内容,操作的也不是原生数据库而是元数据Meta,文中的原生数据库操作也当作复习下,数据库的操作为了同时适合前端和Node开发小伙伴,所以并不是很

程序员成长指北 148 Dec 22, 2022
TypeScript client for Tile38 geo-database

Tile38-ts tier.engineering · Report Bug · Request Feature Table of Contents About The Project Built With Getting Started Requirements Installation Com

Tier Mobility SE 22 Dec 29, 2022
A tiny wrapper around pg that makes PostgreSQL a lot of fun to use. Written in TypeScript.

A tiny wrapper around pg that makes PostgreSQL a lot of fun to use. Written in TypeScript.

Mojolicious 8 Nov 29, 2022
A typescript data mapping tool. To support mutual transforming between domain model and orm entity.

ts-data-mapper A typescript mapping tool supports mutual transforming between domain model and orm entity. In most case, domain model is not fully com

zed 8 Mar 26, 2022
🔄 A realtime Database for JavaScript Applications

RxDB A realtime Database for JavaScript Applications RxDB (short for Reactive Database) is a NoSQL-database for JavaScript Applications like Websites,

Daniel Meyer 18.6k Dec 31, 2022
⚡️ lowdb is a small local JSON database powered by Lodash (supports Node, Electron and the browser)

Lowdb Small JSON database for Node, Electron and the browser. Powered by Lodash. ⚡ db.get('posts') .push({ id: 1, title: 'lowdb is awesome'}) .wri

null 18.9k Dec 30, 2022
:koala: - PouchDB is a pocket-sized database.

PouchDB – The Database that Syncs! PouchDB is an open-source JavaScript database inspired by Apache CouchDB that is designed to run well within the br

PouchDB 15.4k Dec 30, 2022
Execute one command (or mount one Node.js middleware) and get an instant high-performance GraphQL API for your PostgreSQL database!

PostGraphile Instant lightning-fast GraphQL API backed primarily by your PostgreSQL database. Highly customisable and extensible thanks to incredibly

Graphile 11.7k Jan 4, 2023
🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️

A reactive database framework Build powerful React and React Native apps that scale from hundreds to tens of thousands of records and remain fast ⚡️ W

Nozbe 8.8k Jan 5, 2023
AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.

Please use version 1.x as prior versions has a security flaw if you use user generated data to concat your SQL strings instead of providing them as a

Andrey Gershun 6.1k Jan 9, 2023
Realm is a mobile database: an alternative to SQLite & key-value stores

Realm is a mobile database that runs directly inside phones, tablets or wearables. This project hosts the JavaScript versions of Realm. Currently we s

Realm 5.1k Jan 3, 2023
:rocket: One command to generate REST APIs for any MySql Database.

Xmysql : One command to generate REST APIs for any MySql database Why this ? Generating REST APIs for a MySql database which does not follow conventio

null 129 Dec 30, 2022
Realtime database backend based on Operational Transformation (OT)

This README is for [email protected]. For [email protected], see the 1.x-beta branch. To upgrade, see the upgrade guide. ShareDB ShareDB is a realtime databa

ShareJS 5.5k Dec 29, 2022
A transparent, in-memory, streaming write-on-update JavaScript database for Small Web applications that persists to a JavaScript transaction log.

JavaScript Database (JSDB) A zero-dependency, transparent, in-memory, streaming write-on-update JavaScript database for the Small Web that persists to

Small Technology Foundation 237 Nov 13, 2022
The JavaScript Database, for Node.js, nw.js, electron and the browser

The JavaScript Database Embedded persistent or in memory database for Node.js, nw.js, Electron and browsers, 100% JavaScript, no binary dependency. AP

Louis Chatriot 13.2k Jan 2, 2023
Bluzelle is a smart, in-memory data store. It can be used as a cache or as a database.

SwarmDB ABOUT SWARMDB Bluzelle brings together the sharing economy and token economy. Bluzelle enables people to rent out their computer storage space

Bluzelle 225 Dec 31, 2022