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 84ca853948d..e841f574b8e 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 @@ -199,7 +199,6 @@ public abstract class BaseTableColumnTypeTask extends B return new EqualsBuilder() .appendSuper(super.equals(theO)) .append(myColumnType, that.myColumnType) - .append(myColumnTypeToDriverTypeToSqlType, that.myColumnTypeToDriverTypeToSqlType) .append(myNullable, that.myNullable) .append(myColumnLength, that.myColumnLength) .isEquals(); @@ -210,7 +209,6 @@ public abstract class BaseTableColumnTypeTask extends B return new HashCodeBuilder(17, 37) .appendSuper(super.hashCode()) .append(myColumnType) - .append(myColumnTypeToDriverTypeToSqlType) .append(myNullable) .append(myColumnLength) .toHashCode(); diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java index 11460176adb..5b100f2be88 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java @@ -32,10 +32,14 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public abstract class BaseTask { private static final Logger ourLog = LoggerFactory.getLogger(BaseTask.class); + public static final String MIGRATION_VERSION_PATTERN = "\\d{8}\\.\\d+"; + private static final Pattern versionPattern = Pattern.compile(MIGRATION_VERSION_PATTERN); private DriverTypeEnum.ConnectionProperties myConnectionProperties; private DriverTypeEnum myDriverType; private String myDescription; @@ -146,6 +150,13 @@ public abstract class BaseTask { return releasePart + "." + myVersion; } + public void validateVersion() { + Matcher matcher = versionPattern.matcher(myVersion); + if (!matcher.matches()) { + throw new IllegalStateException("The version " + myVersion + " does not match the expected pattern " + MIGRATION_VERSION_PATTERN); + } + } + public static class ExecutedStatement { private final String mySql; private final List myArguments; diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java index ad9472e70d5..187f7da6656 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java @@ -120,7 +120,6 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { // TermValueSetConceptDesignation version.startSectionWithMessage("Processing bulkExportCollectionFile: TRM_VALUESET_C_DESIGNATION"); Builder.BuilderWithTableName termValueSetConceptDesignationTable = version.onTable("TRM_VALUESET_C_DESIGNATION"); - // FIXME KHS validate the version numbers are in order termValueSetConceptDesignationTable.addColumn("20190921.14", "VALUESET_PID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); termValueSetConceptDesignationTable .addForeignKey("FK_TRM_VSCD_VS_PID") @@ -576,7 +575,6 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { spidxToken .addIndex("IDX_SP_TOKEN_HASH") .unique(false) - // FIXME KHS .withColumns("20180903.24.1", "HASH_IDENTITY"); spidxToken .addIndex("IDX_SP_TOKEN_HASH_S") @@ -619,7 +617,6 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { spidxUri .addIndex("IDX_SP_URI_HASH_URI") .unique(false) - // FIXME KHS .withColumns("20180903.27.1", "HASH_URI"); spidxUri .addTask(new CalculateHashesTask(VersionEnum.V3_5_0, "20180903.28") @@ -640,7 +637,6 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { spp .addIndex("IDX_RESPARMPRESENT_HASHPRES") .unique(false) - // FIXME KHS .withColumns("20180903.30.1","HASH_PRESENCE"); ArbitrarySqlTask consolidateSearchParamPresenceIndexesTask = new ArbitrarySqlTask(VersionEnum.V3_5_0, "20180903.31", "HFJ_SEARCH_PARM", "Consolidate search parameter presence indexes"); diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/BaseMigrationTasks.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/BaseMigrationTasks.java index f1365c18ff8..6732766cd9f 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/BaseMigrationTasks.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/BaseMigrationTasks.java @@ -84,12 +84,12 @@ public class BaseMigrationTasks { return retval; } - // FIXME KHS test this void validate(Collection> theTasks) { for (BaseTask task: theTasks) { if (task.isLogMessage()) { continue; } + task.validateVersion(); String version = task.getFlywayVersion(); MigrationVersion migrationVersion = MigrationVersion.fromVersion(version); if (lastVersion != null) { diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIdGeneratorTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIdGeneratorTaskTest.java index aff54c6fe4d..1e3b341c8ae 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIdGeneratorTaskTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIdGeneratorTaskTest.java @@ -19,14 +19,14 @@ public class AddIdGeneratorTaskTest extends BaseTest { public void testAddIdGenerator() throws SQLException { assertThat(JdbcUtils.getSequenceNames(getConnectionProperties()), empty()); - MyMigrationTasks migrator = new MyMigrationTasks(); + MyMigrationTasks migrator = new MyMigrationTasks("123456.7"); getMigrator().addTasks(migrator.getTasks(VersionEnum.V3_3_0, VersionEnum.V3_6_0)); getMigrator().migrate(); assertThat(JdbcUtils.getSequenceNames(getConnectionProperties()), containsInAnyOrder("SEQ_FOO")); // Second time, should produce no action - migrator = new MyMigrationTasks(); + migrator = new MyMigrationTasks("123456.8"); getMigrator().addTasks(migrator.getTasks(VersionEnum.V3_3_0, VersionEnum.V3_6_0)); getMigrator().migrate(); @@ -38,9 +38,9 @@ public class AddIdGeneratorTaskTest extends BaseTest { private static class MyMigrationTasks extends BaseMigrationTasks { - public MyMigrationTasks() { + public MyMigrationTasks(String theVersion) { Builder v = forVersion(VersionEnum.V3_5_0); - v.addIdGenerator("1", "SEQ_FOO"); + v.addIdGenerator(theVersion, "SEQ_FOO"); } diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTaskTest.java new file mode 100644 index 00000000000..82a07ba81d6 --- /dev/null +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTaskTest.java @@ -0,0 +1,50 @@ +package ca.uhn.fhir.jpa.migrate.taskdef; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class BaseTaskTest { + + @Test + public void testValidateVersionCorrect() { + DropTableTask task = new DropTableTask("1", "12345678.9"); + task.validateVersion(); + } + + @Test + public void testValidateVersionShort() { + DropTableTask task = new DropTableTask("1", "123.4"); + try { + task.validateVersion(); + fail(); + } catch (IllegalStateException e) { + assertEquals("The version 123.4 does not match the expected pattern " + BaseTask.MIGRATION_VERSION_PATTERN, e.getMessage()); + } + } + + @Test + public void testValidateVersionNoPeriod() { + DropTableTask task = new DropTableTask("1", "123456789"); + try { + task.validateVersion(); + fail(); + } catch (IllegalStateException e) { + assertEquals("The version 123456789 does not match the expected pattern " + BaseTask.MIGRATION_VERSION_PATTERN, e.getMessage()); + } + } + + @Test + public void testValidateVersionTooManyPeriods() { + DropTableTask task = new DropTableTask("1", "12345678.9.1"); + try { + task.validateVersion(); + fail(); + } catch (IllegalStateException e) { + assertEquals("The version 12345678.9.1 does not match the expected pattern " + BaseTask.MIGRATION_VERSION_PATTERN, e.getMessage()); + } + } + + +} diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java index 18b5b13683a..7593938d305 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java @@ -59,7 +59,7 @@ public class ModifyColumnTest extends BaseTest { public void testNoShrink_SameNullable() throws SQLException { executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255), newcol bigint)"); - ModifyColumnTask task = new ModifyColumnTask("1", "1"); + ModifyColumnTask task = new ModifyColumnTask("1", "123456.7"); task.setTableName("SOMETABLE"); task.setColumnName("TEXTCOL"); task.setColumnType(AddColumnTask.ColumnTypeEnum.STRING);