All tests pass except noShrink case
This commit is contained in:
parent
c7bd11ed0d
commit
6ba3afb489
|
@ -199,7 +199,6 @@ public abstract class BaseTableColumnTypeTask<T extends BaseTableTask> 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<T extends BaseTableTask> extends B
|
|||
return new HashCodeBuilder(17, 37)
|
||||
.appendSuper(super.hashCode())
|
||||
.append(myColumnType)
|
||||
.append(myColumnTypeToDriverTypeToSqlType)
|
||||
.append(myNullable)
|
||||
.append(myColumnLength)
|
||||
.toHashCode();
|
||||
|
|
|
@ -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<T extends 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<T extends 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<Object> myArguments;
|
||||
|
|
|
@ -120,7 +120,6 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
|
|||
// 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<VersionEnum> {
|
|||
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<VersionEnum> {
|
|||
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<VersionEnum> {
|
|||
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");
|
||||
|
|
|
@ -84,12 +84,12 @@ public class BaseMigrationTasks<T extends Enum> {
|
|||
return retval;
|
||||
}
|
||||
|
||||
// FIXME KHS test this
|
||||
void validate(Collection<BaseTask<?>> theTasks) {
|
||||
for (BaseTask task: theTasks) {
|
||||
if (task.isLogMessage()) {
|
||||
continue;
|
||||
}
|
||||
task.validateVersion();
|
||||
String version = task.getFlywayVersion();
|
||||
MigrationVersion migrationVersion = MigrationVersion.fromVersion(version);
|
||||
if (lastVersion != null) {
|
||||
|
|
|
@ -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<VersionEnum> {
|
||||
|
||||
public MyMigrationTasks() {
|
||||
public MyMigrationTasks(String theVersion) {
|
||||
Builder v = forVersion(VersionEnum.V3_5_0);
|
||||
v.addIdGenerator("1", "SEQ_FOO");
|
||||
v.addIdGenerator(theVersion, "SEQ_FOO");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue