飞行路线如何对版本号进行排序



如果我们有这样的迁移:

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

我们应该为下一个版本使用什么?

如果我们使用V1_10那会在V1__9之后出现吗?还是我们需要在个位数版本号前面加上0

真正的问题是:版本号是按数字还是按字母顺序排序?

一个词:数字。正如对一个数字所期望的那样。

有关排序如何发生的明确答案,您可以参考代码。这个测试特别有用。

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

最新更新