Skip to content

Commit

Permalink
fix: Keep total order of migrations intact. (#1343)
Browse files Browse the repository at this point in the history
The total order of migrations was not correctly recorded when a
repeatable migration was followed by 2 or more migrations that had
already been applied and a new one was added after those.

Fixes #1342.
  • Loading branch information
michael-simons committed Jun 13, 2024
1 parent 39145ba commit 4574c2c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ private void apply0(List<Migration> migrations) {
repeated = true;
} else {
LOGGER.log(Level.INFO, "Skipping already applied migration {0}", toString(migration));
previousVersion = migration.getVersion();
continue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,37 @@ void shouldAllowCallInTX(String script) {
assertThat(appliedMigrations).isEqualTo(1);
}

@Test // 1342
void addingMigrationsAfterRepeatingOnesMustNotFail() {

var config = MigrationsConfig.builder().withLocationsToScan("classpath:repeatable/original", "classpath:repeatable/constant")
.build();

var migrations = new Migrations(config, driver);
migrations.clean(false);
migrations.info();
migrations.apply();

config = MigrationsConfig.builder().withLocationsToScan("classpath:repeatable/modified", "classpath:repeatable/constant", "classpath:repeatable/added")
.build();

migrations = new Migrations(config, driver);
migrations.apply();

// If chain is wrong, this would fail
assertThatNoException().isThrownBy(migrations::apply);

var records = driver.executableQuery("""
MATCH (:`__Neo4jMigration` {version:'BASELINE'}) (()-[:MIGRATED_TO]->()){4} (t:`__Neo4jMigration`)
RETURN t.version AS version
""").execute().records();
assertThat(records).hasSize(1).first().extracting(r -> r.get("version").asString()).isEqualTo("004");

var repetitionCnt = driver.executableQuery("MATCH (n:`__Neo4jMigration` {version: '001'})-[r:REPEATED]->(n) RETURN count(r) AS cnt")
.execute().records().get(0).get("cnt").asLong();
assertThat(repetitionCnt).isOne();
}

@Nested
class Repairing {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE (n:V004);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE (n:V001);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE (n:V001);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE (n:R1Modified);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE (n:R1);

0 comments on commit 4574c2c

Please sign in to comment.