marianozunino/morpheus

Support Write and Schema modification

maximeSurmontGH opened this issue · 5 comments

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.

Hey @maximeSurmontGH 👋

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.

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();

Oh neat! 👍
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

Damn unbelievable !