diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/FlywayMigrator.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/FlywayMigrator.java index 382dcfd2618..3853cb926a7 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/FlywayMigrator.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/FlywayMigrator.java @@ -20,7 +20,6 @@ package ca.uhn.fhir.jpa.migrate; * #L% */ -import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.jpa.migrate.taskdef.BaseTask; import com.google.common.annotations.VisibleForTesting; import org.apache.commons.dbcp2.BasicDataSource; @@ -30,7 +29,6 @@ import org.flywaydb.core.api.migration.JavaMigration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.sql.Driver; import java.util.ArrayList; import java.util.List; @@ -93,7 +91,7 @@ public class FlywayMigrator { Flyway flyway = initFlyway(connectionProperties); flyway.migrate(); } catch (Exception e) { - throw new ConfigurationException("Failed to migrate schema", e); + throw e; } } diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTableColumnTypeTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTableColumnTypeTask.java index 493cdcf084f..d7c401b7cb6 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTableColumnTypeTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTableColumnTypeTask.java @@ -21,13 +21,12 @@ package ca.uhn.fhir.jpa.migrate.taskdef; */ import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; -import ca.uhn.fhir.jpa.migrate.FlywayMigration; import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.util.Assert; import java.util.HashMap; import java.util.Map; @@ -207,7 +206,7 @@ public abstract class BaseTableColumnTypeTask extends B return new EqualsBuilder() .appendSuper(super.equals(theO)) - .append(myColumnType.name(), that.myColumnType.name()) + .append(getColumnTypeName(myColumnType), getColumnTypeName(that.myColumnType)) .append(myNullable, that.myNullable) .append(myColumnLength, that.myColumnLength) .isEquals(); @@ -217,9 +216,17 @@ public abstract class BaseTableColumnTypeTask extends B public int hashCode() { return new HashCodeBuilder(17, 37) .appendSuper(super.hashCode()) - .append(myColumnType.name()) + .append(getColumnTypeName(myColumnType)) .append(myNullable) .append(myColumnLength) .toHashCode(); } + + @Nullable + private Object getColumnTypeName(ColumnTypeEnum theColumnType) { + if (theColumnType == null) { + return null; + } + return myColumnType.name(); + } } diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTest.java index 183cda99f9b..29aabf4245b 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTest.java @@ -2,14 +2,17 @@ package ca.uhn.fhir.jpa.migrate.taskdef; import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; import ca.uhn.fhir.jpa.migrate.FlywayMigrator; +import ca.uhn.fhir.jpa.migrate.JdbcUtils; import org.apache.commons.dbcp2.BasicDataSource; import org.intellij.lang.annotations.Language; import org.junit.After; import org.junit.Before; import org.springframework.jdbc.core.ColumnMapRowMapper; +import java.sql.SQLException; import java.util.List; import java.util.Map; +import java.util.Set; public class BaseTest { @@ -46,8 +49,11 @@ public class BaseTest { } @After - public void resetMigrationVersion() { + public void resetMigrationVersion() throws SQLException { + Set tableNames = JdbcUtils.getTableNames(getConnectionProperties()); + if (tableNames.contains("flyway_schema_history")) { executeSql("DELETE from \"flyway_schema_history\" where \"installed_rank\" > 0"); + } } protected void executeSql(@Language("SQL") String theSql, Object... theArgs) {