Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does flyway sort version numbers?

Tags:

flyway

If we have migrations like:

V1_6__six.sql
V1_7__seven.sql
V1_8__eight.sql
V1_9__nine.sql

What should we use for the next version?

If we use V1_10 will that come after V1__9? Or would we need to prefix the single digit version numbers with a 0?

Really the question is: are version numbers sorted numerically or alphabetically?

like image 264
Marplesoft Avatar asked Nov 14 '13 17:11

Marplesoft


People also ask

How does a Flyway script work?

How Does Flyway Work? Flyway works by checking the current version of the database and by applying new migrations automatically before the rest of the application starts.

Does Flyway create schema?

Schema creationBy default, Flyway will attempt to create the schemas provided by the schemas and defaultSchema configuration options. This behavior can be toggled with the createSchemas configuration option. This might be useful when you want complete control over how schemas are created.

Which is better Flyway or Liquibase?

While both tools are based on Martin Fowler's Evolutionary Database, there are many differences in what these tools offer. Here's where Liquibase and Flyway differ. The bottom line is that Liquibase is more powerful and flexible — covering more database change and deployment use cases than Flyway.

Does Flyway migrate data?

Flyway updates a database from one version to the next using migrations. We can write migrations either in SQL with database-specific syntax, or in Java for advanced database transformations.


2 Answers

In one word: numerically. As would be expected for a number.

like image 162
Axel Fontaine Avatar answered Sep 25 '22 21:09

Axel Fontaine


For a definitive answer on how the sorting happens, you can refer to the code. This test is especially helpful.

@Test
public void testNumber() {
    final MigrationVersion a1 = MigrationVersion.fromVersion("1.2.13.3");
    final MigrationVersion a2 = MigrationVersion.fromVersion("1.2.3.3");
    assertTrue(a1.compareTo(a2) > 0);
}

@Test
public void testLength1() {
    final MigrationVersion a1 = MigrationVersion.fromVersion("1.2.1.3");
    final MigrationVersion a2 = MigrationVersion.fromVersion("1.2.1");
    assertTrue(a1.compareTo(a2) > 0);
}

@Test
public void testLength2() {
    final MigrationVersion a1 = MigrationVersion.fromVersion("1.2.1");
    final MigrationVersion a2 = MigrationVersion.fromVersion("1.2.1.1");
    assertTrue(a1.compareTo(a2) < 0);
}

@Test
public void leadingZeroes() {
    final MigrationVersion v1 = MigrationVersion.fromVersion("1.0");
    final MigrationVersion v2 = MigrationVersion.fromVersion("001.0");
    assertTrue(v1.compareTo(v2) == 0);
    assertTrue(v1.equals(v2));
    assertEquals(v1.hashCode(), v2.hashCode());
}
like image 29
David W Avatar answered Sep 26 '22 21:09

David W