This commit is contained in:
Ken Stevens 2019-11-02 21:51:17 -04:00
parent 8ee06855d7
commit becd6790e8
3 changed files with 19 additions and 8 deletions

View File

@ -20,7 +20,6 @@ package ca.uhn.fhir.jpa.migrate;
* #L% * #L%
*/ */
import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.jpa.migrate.taskdef.BaseTask; import ca.uhn.fhir.jpa.migrate.taskdef.BaseTask;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.dbcp2.BasicDataSource;
@ -30,7 +29,6 @@ import org.flywaydb.core.api.migration.JavaMigration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.sql.Driver;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -93,7 +91,7 @@ public class FlywayMigrator {
Flyway flyway = initFlyway(connectionProperties); Flyway flyway = initFlyway(connectionProperties);
flyway.migrate(); flyway.migrate();
} catch (Exception e) { } catch (Exception e) {
throw new ConfigurationException("Failed to migrate schema", e); throw e;
} }
} }

View File

@ -21,13 +21,12 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
*/ */
import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; 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.Validate;
import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -207,7 +206,7 @@ public abstract class BaseTableColumnTypeTask<T extends BaseTableTask> extends B
return new EqualsBuilder() return new EqualsBuilder()
.appendSuper(super.equals(theO)) .appendSuper(super.equals(theO))
.append(myColumnType.name(), that.myColumnType.name()) .append(getColumnTypeName(myColumnType), getColumnTypeName(that.myColumnType))
.append(myNullable, that.myNullable) .append(myNullable, that.myNullable)
.append(myColumnLength, that.myColumnLength) .append(myColumnLength, that.myColumnLength)
.isEquals(); .isEquals();
@ -217,9 +216,17 @@ public abstract class BaseTableColumnTypeTask<T extends BaseTableTask> extends B
public int hashCode() { public int hashCode() {
return new HashCodeBuilder(17, 37) return new HashCodeBuilder(17, 37)
.appendSuper(super.hashCode()) .appendSuper(super.hashCode())
.append(myColumnType.name()) .append(getColumnTypeName(myColumnType))
.append(myNullable) .append(myNullable)
.append(myColumnLength) .append(myColumnLength)
.toHashCode(); .toHashCode();
} }
@Nullable
private Object getColumnTypeName(ColumnTypeEnum theColumnType) {
if (theColumnType == null) {
return null;
}
return myColumnType.name();
}
} }

View File

@ -2,14 +2,17 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
import ca.uhn.fhir.jpa.migrate.FlywayMigrator; import ca.uhn.fhir.jpa.migrate.FlywayMigrator;
import ca.uhn.fhir.jpa.migrate.JdbcUtils;
import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.dbcp2.BasicDataSource;
import org.intellij.lang.annotations.Language; import org.intellij.lang.annotations.Language;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.springframework.jdbc.core.ColumnMapRowMapper; import org.springframework.jdbc.core.ColumnMapRowMapper;
import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
public class BaseTest { public class BaseTest {
@ -46,8 +49,11 @@ public class BaseTest {
} }
@After @After
public void resetMigrationVersion() { public void resetMigrationVersion() throws SQLException {
Set<String> tableNames = JdbcUtils.getTableNames(getConnectionProperties());
if (tableNames.contains("flyway_schema_history")) {
executeSql("DELETE from \"flyway_schema_history\" where \"installed_rank\" > 0"); executeSql("DELETE from \"flyway_schema_history\" where \"installed_rank\" > 0");
}
} }
protected void executeSql(@Language("SQL") String theSql, Object... theArgs) { protected void executeSql(@Language("SQL") String theSql, Object... theArgs) {