How does flyway sort version numbers?

佐手、 提交于 2019-12-08 15:53:25

问题


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?


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/19984397/how-does-flyway-sort-version-numbers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!