marianozunino / morpheus

Morpheus is a modern, open-source database migration tool for Neo4j. It is designed to be a simple, intuitive tool for managing database migrations. The project is inspired by Michael Simons' tool for Java.
MIT License
19 stars 4 forks source link

Support Write and Schema modification #10

Closed maximeSurmontGH closed 2 years ago

maximeSurmontGH commented 2 years ago

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.

marianozunino commented 2 years ago

Hey @maximeSurmontGH :wave:

Each migration statement runs inside of a transaction and that's intentional (following Michael's design). But, I found out that I wasn't able to run one of your statements because the transaction was shared with the creation of the Migration Node. So, I'll push the fix asap. Regarding your issue, you should use 2 migration files for those statements.

maximeSurmontGH commented 2 years ago

Oh yes works well thanks !

Just for your information (don t know if it does interest you), I am not using it with the CLI but when the application is starting :)

// ./src/main.ts

// some imports
import { Migrator } from 'morpheus4j/dist/migrator';
import { repositoryFactory } from 'morpheus4j/dist/utils';

async function bootstrap() {
    const app = await NestFactory.create(AppModule);

        // some code

    const neo4jMigrationRepository = await repositoryFactory();
    const neo4jMigrationRunner = new Migrator(neo4jMigrationRepository);
    await neo4jMigrationRunner.migrate();

    await app.listen(PORT, HOST_NAME);
}
bootstrap();
marianozunino commented 2 years ago

Oh neat! :+1: I initially wanted to write this using Nest (there's a Nest CLI module) but I thought that it was a bit overkill since nobody would use this as an API. Now I'm regretting that decision lol

marianozunino commented 2 years ago

@maximeSurmontGH https://github.com/marianozunino/morpheus#nestjs-integration :wink:

maximeSurmontGH commented 2 years ago

Damn unbelievable !