Ejemplo n.º 1
0
  @Test
  public void outOfOrder() {
    DriverDataSource dataSource =
        new DriverDataSource(null, "jdbc:h2:mem:flyway_out_of_order;DB_CLOSE_DELAY=-1", "sa", "");

    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.setLocations("migration/sql");
    flyway.setTarget(new MigrationVersion("1.2"));
    assertEquals(4, flyway.info().all().length);
    assertEquals(3, flyway.info().pending().length);

    flyway.clean();
    assertEquals(3, flyway.migrate());
    assertEquals(0, flyway.info().pending().length);

    flyway.setLocations("migration/sql", "migration/outoforder");
    assertEquals(5, flyway.info().all().length);
    assertEquals(MigrationState.IGNORED, flyway.info().all()[2].getState());
    assertEquals(0, flyway.migrate());

    flyway.setTarget(MigrationVersion.LATEST);
    flyway.setOutOfOrder(true);
    assertEquals(MigrationState.PENDING, flyway.info().all()[2].getState());
    assertEquals(2, flyway.migrate());

    assertEquals(MigrationState.OUT_OF_ORDER, flyway.info().all()[2].getState());
    assertEquals(MigrationState.SUCCESS, flyway.info().all()[4].getState());
  }