use of org.flywaydb.core.api.FlywayException in project flyway by flyway.
the class FlywayMediumTest method repairFirst.
@Test
public void repairFirst() throws Exception {
DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_repair;DB_CLOSE_DELAY=-1", "sa", "", null, "SET AUTOCOMMIT OFF");
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
Map<String, String> placeholders = new HashMap<String, String>();
placeholders.put("tableName", "aaa");
flyway.setPlaceholders(placeholders);
flyway.setLocations("migration/failed");
assertEquals(1, flyway.info().all().length);
try {
flyway.migrate();
} catch (FlywayException e) {
//Should happen
}
assertEquals("1", flyway.info().current().getVersion().toString());
assertEquals(MigrationState.FAILED, flyway.info().current().getState());
flyway.repair();
assertNull(flyway.info().current());
}
use of org.flywaydb.core.api.FlywayException in project flyway by flyway.
the class FlywayMediumTest method repeatableFailed.
@Test
public void repeatableFailed() {
DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_repeatable_failed;DB_CLOSE_DELAY=-1", "sa", "", null);
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setLocations("migration/repeatable_failed");
try {
flyway.migrate();
fail();
} catch (FlywayException e) {
assertEquals(e.getMessage(), MigrationState.FAILED, flyway.info().current().getState());
}
try {
flyway.validate();
fail();
} catch (FlywayException e) {
assertTrue(e.getMessage(), e.getMessage().contains("failed repeatable migration"));
}
flyway.setLocations("migration/repeatable");
try {
flyway.migrate();
fail();
} catch (FlywayException e) {
assertTrue(e.getMessage(), e.getMessage().contains("failed repeatable migration"));
}
}
use of org.flywaydb.core.api.FlywayException in project flyway by flyway.
the class FlywayMediumTest method cleanDisabled.
@Test(expected = FlywayException.class)
public void cleanDisabled() throws Exception {
DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_clean_disabled;DB_CLOSE_DELAY=-1", "sa", "", null);
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
try {
flyway.clean();
} catch (FlywayException e) {
fail("clean should succeed when cleanDisabled is false");
}
flyway.setCleanDisabled(true);
flyway.clean();
}
use of org.flywaydb.core.api.FlywayException in project flyway by flyway.
the class DbSupportFactory method getDatabaseProductName.
/**
* Retrieves the name of the database product.
*
* @param connection The connection to use to query the database.
* @return The name of the database product. Ex.: Oracle, MySQL, ...
*/
private static String getDatabaseProductName(Connection connection) {
try {
DatabaseMetaData databaseMetaData = connection.getMetaData();
if (databaseMetaData == null) {
throw new FlywayException("Unable to read database metadata while it is null!");
}
String databaseProductName = databaseMetaData.getDatabaseProductName();
if (databaseProductName == null) {
throw new FlywayException("Unable to determine database. Product name is null.");
}
int databaseMajorVersion = databaseMetaData.getDatabaseMajorVersion();
int databaseMinorVersion = databaseMetaData.getDatabaseMinorVersion();
return databaseProductName + " " + databaseMajorVersion + "." + databaseMinorVersion;
} catch (SQLException e) {
throw new FlywaySqlException("Error while determining database product name", e);
}
}
use of org.flywaydb.core.api.FlywayException in project flyway by flyway.
the class DbSupportFactory method getDriverName.
/**
* Retrieves the name of the JDBC driver
*
* @param connection The connection to use to query the database.
* @return The name of the driver. Ex: RedshiftJDBC
*/
private static String getDriverName(Connection connection) {
try {
DatabaseMetaData databaseMetaData = connection.getMetaData();
if (databaseMetaData == null) {
throw new FlywayException("Unable to read database metadata while it is null!");
}
String driverName = databaseMetaData.getDriverName();
if (driverName == null) {
throw new FlywayException("Unable to determine JDBC driver name. JDBC driver name is null.");
}
return driverName;
} catch (SQLException e) {
throw new FlywaySqlException("Error while determining JDBC driver name", e);
}
}
Aggregations