All tests pass except noShrink case

This commit is contained in:
Ken Stevens 2019-10-29 15:30:25 -04:00
parent c7bd11ed0d
commit 6ba3afb489
7 changed files with 67 additions and 12 deletions

View File

@ -199,7 +199,6 @@ 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, that.myColumnType) .append(myColumnType, that.myColumnType)
.append(myColumnTypeToDriverTypeToSqlType, that.myColumnTypeToDriverTypeToSqlType)
.append(myNullable, that.myNullable) .append(myNullable, that.myNullable)
.append(myColumnLength, that.myColumnLength) .append(myColumnLength, that.myColumnLength)
.isEquals(); .isEquals();
@ -210,7 +209,6 @@ public abstract class BaseTableColumnTypeTask<T extends BaseTableTask> extends B
return new HashCodeBuilder(17, 37) return new HashCodeBuilder(17, 37)
.appendSuper(super.hashCode()) .appendSuper(super.hashCode())
.append(myColumnType) .append(myColumnType)
.append(myColumnTypeToDriverTypeToSqlType)
.append(myNullable) .append(myNullable)
.append(myColumnLength) .append(myColumnLength)
.toHashCode(); .toHashCode();

View File

@ -32,10 +32,14 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class BaseTask<T extends BaseTask> { public abstract class BaseTask<T extends BaseTask> {
private static final Logger ourLog = LoggerFactory.getLogger(BaseTask.class); 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.ConnectionProperties myConnectionProperties;
private DriverTypeEnum myDriverType; private DriverTypeEnum myDriverType;
private String myDescription; private String myDescription;
@ -146,6 +150,13 @@ public abstract class BaseTask<T extends BaseTask> {
return releasePart + "." + myVersion; 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 { public static class ExecutedStatement {
private final String mySql; private final String mySql;
private final List<Object> myArguments; private final List<Object> myArguments;

View File

@ -120,7 +120,6 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
// TermValueSetConceptDesignation // TermValueSetConceptDesignation
version.startSectionWithMessage("Processing bulkExportCollectionFile: TRM_VALUESET_C_DESIGNATION"); version.startSectionWithMessage("Processing bulkExportCollectionFile: TRM_VALUESET_C_DESIGNATION");
Builder.BuilderWithTableName termValueSetConceptDesignationTable = version.onTable("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.addColumn("20190921.14", "VALUESET_PID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG);
termValueSetConceptDesignationTable termValueSetConceptDesignationTable
.addForeignKey("FK_TRM_VSCD_VS_PID") .addForeignKey("FK_TRM_VSCD_VS_PID")
@ -576,7 +575,6 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
spidxToken spidxToken
.addIndex("IDX_SP_TOKEN_HASH") .addIndex("IDX_SP_TOKEN_HASH")
.unique(false) .unique(false)
// FIXME KHS
.withColumns("20180903.24.1", "HASH_IDENTITY"); .withColumns("20180903.24.1", "HASH_IDENTITY");
spidxToken spidxToken
.addIndex("IDX_SP_TOKEN_HASH_S") .addIndex("IDX_SP_TOKEN_HASH_S")
@ -619,7 +617,6 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
spidxUri spidxUri
.addIndex("IDX_SP_URI_HASH_URI") .addIndex("IDX_SP_URI_HASH_URI")
.unique(false) .unique(false)
// FIXME KHS
.withColumns("20180903.27.1", "HASH_URI"); .withColumns("20180903.27.1", "HASH_URI");
spidxUri spidxUri
.addTask(new CalculateHashesTask(VersionEnum.V3_5_0, "20180903.28") .addTask(new CalculateHashesTask(VersionEnum.V3_5_0, "20180903.28")
@ -640,7 +637,6 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
spp spp
.addIndex("IDX_RESPARMPRESENT_HASHPRES") .addIndex("IDX_RESPARMPRESENT_HASHPRES")
.unique(false) .unique(false)
// FIXME KHS
.withColumns("20180903.30.1","HASH_PRESENCE"); .withColumns("20180903.30.1","HASH_PRESENCE");
ArbitrarySqlTask consolidateSearchParamPresenceIndexesTask = new ArbitrarySqlTask(VersionEnum.V3_5_0, "20180903.31", "HFJ_SEARCH_PARM", "Consolidate search parameter presence indexes"); ArbitrarySqlTask consolidateSearchParamPresenceIndexesTask = new ArbitrarySqlTask(VersionEnum.V3_5_0, "20180903.31", "HFJ_SEARCH_PARM", "Consolidate search parameter presence indexes");

View File

@ -84,12 +84,12 @@ public class BaseMigrationTasks<T extends Enum> {
return retval; return retval;
} }
// FIXME KHS test this
void validate(Collection<BaseTask<?>> theTasks) { void validate(Collection<BaseTask<?>> theTasks) {
for (BaseTask task: theTasks) { for (BaseTask task: theTasks) {
if (task.isLogMessage()) { if (task.isLogMessage()) {
continue; continue;
} }
task.validateVersion();
String version = task.getFlywayVersion(); String version = task.getFlywayVersion();
MigrationVersion migrationVersion = MigrationVersion.fromVersion(version); MigrationVersion migrationVersion = MigrationVersion.fromVersion(version);
if (lastVersion != null) { if (lastVersion != null) {

View File

@ -19,14 +19,14 @@ public class AddIdGeneratorTaskTest extends BaseTest {
public void testAddIdGenerator() throws SQLException { public void testAddIdGenerator() throws SQLException {
assertThat(JdbcUtils.getSequenceNames(getConnectionProperties()), empty()); 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().addTasks(migrator.getTasks(VersionEnum.V3_3_0, VersionEnum.V3_6_0));
getMigrator().migrate(); getMigrator().migrate();
assertThat(JdbcUtils.getSequenceNames(getConnectionProperties()), containsInAnyOrder("SEQ_FOO")); assertThat(JdbcUtils.getSequenceNames(getConnectionProperties()), containsInAnyOrder("SEQ_FOO"));
// Second time, should produce no action // 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().addTasks(migrator.getTasks(VersionEnum.V3_3_0, VersionEnum.V3_6_0));
getMigrator().migrate(); getMigrator().migrate();
@ -38,9 +38,9 @@ public class AddIdGeneratorTaskTest extends BaseTest {
private static class MyMigrationTasks extends BaseMigrationTasks<VersionEnum> { private static class MyMigrationTasks extends BaseMigrationTasks<VersionEnum> {
public MyMigrationTasks() { public MyMigrationTasks(String theVersion) {
Builder v = forVersion(VersionEnum.V3_5_0); Builder v = forVersion(VersionEnum.V3_5_0);
v.addIdGenerator("1", "SEQ_FOO"); v.addIdGenerator(theVersion, "SEQ_FOO");
} }

View File

@ -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());
}
}
}

View File

@ -59,7 +59,7 @@ public class ModifyColumnTest extends BaseTest {
public void testNoShrink_SameNullable() throws SQLException { public void testNoShrink_SameNullable() throws SQLException {
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255), newcol bigint)"); 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.setTableName("SOMETABLE");
task.setColumnName("TEXTCOL"); task.setColumnName("TEXTCOL");
task.setColumnType(AddColumnTask.ColumnTypeEnum.STRING); task.setColumnType(AddColumnTask.ColumnTypeEnum.STRING);