all done but reversioning

This commit is contained in:
Ken Stevens 2019-10-29 18:03:13 -04:00
parent 6ba3afb489
commit 28e628ec0e
8 changed files with 35 additions and 96 deletions

View File

@ -66,10 +66,8 @@ public class FlywayMigrator {
} }
public void addTask(BaseTask<?> theTask) { public void addTask(BaseTask<?> theTask) {
if (!theTask.isLogMessage()) {
myTasks.add(new FlywayMigration(theTask, this)); myTasks.add(new FlywayMigration(theTask, this));
} }
}
public void setDryRun(boolean theDryRun) { public void setDryRun(boolean theDryRun) {
myDryRun = theDryRun; myDryRun = theDryRun;

View File

@ -141,11 +141,15 @@ public abstract class BaseTableColumnTypeTask<T extends BaseTableTask> extends B
} }
protected String getSqlType() { protected String getSqlType() {
return getSqlType(getColumnLength());
}
protected String getSqlType(Long theColumnLength) {
String retVal = myColumnTypeToDriverTypeToSqlType.get(myColumnType).get(getDriverType()); String retVal = myColumnTypeToDriverTypeToSqlType.get(myColumnType).get(getDriverType());
Objects.requireNonNull(retVal); Objects.requireNonNull(retVal);
if (myColumnType == ColumnTypeEnum.STRING) { if (myColumnType == ColumnTypeEnum.STRING) {
retVal = retVal.replace("?", Long.toString(getColumnLength())); retVal = retVal.replace("?", Long.toString(theColumnLength));
} }
return retVal; return retVal;

View File

@ -180,9 +180,4 @@ public abstract class BaseTask<T extends BaseTask> {
return myArguments; return myArguments;
} }
} }
// FIXME KHS find a way to put these back in
public boolean isLogMessage() {
return false;
}
} }

View File

@ -1,53 +0,0 @@
package ca.uhn.fhir.jpa.migrate.taskdef;
/*-
* #%L
* HAPI FHIR JPA Server - Migration
* %%
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LogStartSectionWithMessageTask extends BaseTask {
private static final Logger ourLog = LoggerFactory.getLogger(LogStartSectionWithMessageTask.class);
private final String myMessage;
public LogStartSectionWithMessageTask(String theMessage) {
super(null, null);
myMessage = theMessage;
}
@Override
public void validate() {
// nothing
}
@Override
public void execute() {
ourLog.info("");
ourLog.info(StringUtils.leftPad("", myMessage.length(), "*"));
ourLog.info(myMessage);
ourLog.info(StringUtils.leftPad("", myMessage.length(), "*"));
}
@Override
public boolean isLogMessage() {
return true;
}
}

View File

@ -60,21 +60,22 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask<ModifyColumnTask>
throw new InternalErrorException(e); throw new InternalErrorException(e);
} }
if (getColumnLength() != null && isNoColumnShrink()) { Long columnLength = getColumnLength();
if (columnLength != null && isNoColumnShrink()) {
long existingLength = existingType.getLength() != null ? existingType.getLength() : 0; long existingLength = existingType.getLength() != null ? existingType.getLength() : 0;
if (existingLength > getColumnLength()) { if (existingLength > columnLength) {
setColumnLength(existingLength); columnLength = existingLength;
} }
} }
boolean alreadyOfCorrectType = existingType.equals(getColumnType(), getColumnLength()); boolean alreadyOfCorrectType = existingType.equals(getColumnType(), columnLength);
boolean alreadyCorrectNullable = isNullable() == nullable; boolean alreadyCorrectNullable = isNullable() == nullable;
if (alreadyOfCorrectType && alreadyCorrectNullable) { if (alreadyOfCorrectType && alreadyCorrectNullable) {
ourLog.info("Column {} on table {} is already of type {} and has nullable {} - No action performed", getColumnName(), getTableName(), existingType, nullable); ourLog.info("Column {} on table {} is already of type {} and has nullable {} - No action performed", getColumnName(), getTableName(), existingType, nullable);
return; return;
} }
String type = getSqlType(); String type = getSqlType(columnLength);
String notNull = getSqlNotNull(); String notNull = getSqlNotNull();
String sql = null; String sql = null;

View File

@ -50,15 +50,15 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
.map(FlagEnum::fromCommandLineValue) .map(FlagEnum::fromCommandLineValue)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
init330(); init330(); // 20180114 - 20180329
init340(); init340(); // 20180401 - 20180528
init350(); init350(); // 20180601 - 20180917
init360(); init360(); // 20180918 - 20181112
init400(); init400(); // 20190401 - 20190814
init410(); init410(); // 20190815 - present
} }
protected void init410() { protected void init410() { // 20190815 - present
Builder version = forVersion(VersionEnum.V4_1_0); Builder version = forVersion(VersionEnum.V4_1_0);
// HFJ_SEARCH // HFJ_SEARCH
@ -170,7 +170,7 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
version.onTable("TRM_CONCEPT_PROPERTY").addColumn("20191002.9", "PROP_VAL_LOB").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.BLOB); version.onTable("TRM_CONCEPT_PROPERTY").addColumn("20191002.9", "PROP_VAL_LOB").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.BLOB);
} }
protected void init400() { protected void init400() { // 20190401 - 20190814
Builder version = forVersion(VersionEnum.V4_0_0); Builder version = forVersion(VersionEnum.V4_0_0);
// BinaryStorageEntity // BinaryStorageEntity
@ -359,7 +359,7 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
} }
private void init360() { private void init360() { // 20180918 - 20181112
Builder version = forVersion(VersionEnum.V3_6_0); Builder version = forVersion(VersionEnum.V3_6_0);
// Resource Link // Resource Link
@ -396,7 +396,7 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
} }
private void init350() { private void init350() { // 20180601 - 20180917
Builder version = forVersion(VersionEnum.V3_5_0); Builder version = forVersion(VersionEnum.V3_5_0);
// Forced ID changes // Forced ID changes
@ -831,47 +831,47 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
return longValue == 1L; return longValue == 1L;
} }
private void init340() { private void init340() { // 20180401 - 20180528
Builder version = forVersion(VersionEnum.V3_4_0); Builder version = forVersion(VersionEnum.V3_4_0);
// CodeSystem Version // CodeSystem Version
Builder.BuilderWithTableName resourceLink = version.onTable("TRM_CODESYSTEM_VER"); Builder.BuilderWithTableName resourceLink = version.onTable("TRM_CODESYSTEM_VER");
version.startSectionWithMessage("Starting work on table: " + resourceLink.getTableName()); version.startSectionWithMessage("Starting work on table: " + resourceLink.getTableName());
resourceLink resourceLink
.dropIndex("20180929.1", "IDX_CSV_RESOURCEPID_AND_VER"); .dropIndex("20180401.1", "IDX_CSV_RESOURCEPID_AND_VER");
resourceLink resourceLink
.dropColumn("20180929.2", "RES_VERSION_ID"); .dropColumn("20180401.2", "RES_VERSION_ID");
resourceLink resourceLink
.addColumn("20180929.3", "CS_VERSION_ID") .addColumn("20180401.3", "CS_VERSION_ID")
.nullable() .nullable()
.type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 255); .type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 255);
resourceLink resourceLink
.addColumn("20180929.4", "CODESYSTEM_PID") .addColumn("20180401.4", "CODESYSTEM_PID")
.nullable() .nullable()
.type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); .type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG);
resourceLink resourceLink
.addForeignKey("FK_CODESYSVER_CS_ID") .addForeignKey("FK_CODESYSVER_CS_ID")
.toColumn("CODESYSTEM_PID") .toColumn("CODESYSTEM_PID")
.references("20180929.5", "TRM_CODESYSTEM", "PID"); .references("20180401.5", "TRM_CODESYSTEM", "PID");
// Concept // Concept
Builder.BuilderWithTableName concept = version.onTable("TRM_CONCEPT"); Builder.BuilderWithTableName concept = version.onTable("TRM_CONCEPT");
version.startSectionWithMessage("Starting work on table: " + concept.getTableName()); version.startSectionWithMessage("Starting work on table: " + concept.getTableName());
concept concept
.addColumn("20180929.6", "CODE_SEQUENCE") .addColumn("20180401.6", "CODE_SEQUENCE")
.nullable() .nullable()
.type(BaseTableColumnTypeTask.ColumnTypeEnum.INT); .type(BaseTableColumnTypeTask.ColumnTypeEnum.INT);
} }
private void init330() { private void init330() { // 20180114 - 20180329
Builder version = forVersion(VersionEnum.V3_3_0); Builder version = forVersion(VersionEnum.V3_3_0);
Builder.BuilderWithTableName hfjResource = version.onTable("HFJ_RESOURCE"); Builder.BuilderWithTableName hfjResource = version.onTable("HFJ_RESOURCE");
version.startSectionWithMessage("Starting work on table: " + hfjResource.getTableName()); version.startSectionWithMessage("Starting work on table: " + hfjResource.getTableName());
hfjResource.dropColumn("20180601.1", "RES_TEXT"); hfjResource.dropColumn("20180114.1", "RES_TEXT");
hfjResource.dropColumn("20180601.2", "RES_ENCODING"); hfjResource.dropColumn("20180114.2", "RES_ENCODING");
Builder.BuilderWithTableName hfjResVer = version.onTable("HFJ_RES_VER"); Builder.BuilderWithTableName hfjResVer = version.onTable("HFJ_RES_VER");
version.startSectionWithMessage("Starting work on table: " + hfjResVer.getTableName()); version.startSectionWithMessage("Starting work on table: " + hfjResVer.getTableName());

View File

@ -71,9 +71,6 @@ public class BaseMigrationTasks<T extends Enum> {
public List<BaseTask<?>> getAllTasks(T[] theVersionEnumValues) { public List<BaseTask<?>> getAllTasks(T[] theVersionEnumValues) {
List<BaseTask<?>> retval = new ArrayList<>(); List<BaseTask<?>> retval = new ArrayList<>();
for (T nextVersion : theVersionEnumValues) { for (T nextVersion : theVersionEnumValues) {
retval.add(new LogStartSectionWithMessageTask("------------------------------------------------"));
retval.add(new LogStartSectionWithMessageTask("Starting migrations for version " + nextVersion));
retval.add(new LogStartSectionWithMessageTask("------------------------------------------------"));
Collection<BaseTask<?>> nextValues = myTasks.get(nextVersion); Collection<BaseTask<?>> nextValues = myTasks.get(nextVersion);
if (nextValues != null) { if (nextValues != null) {
validate(nextValues); validate(nextValues);
@ -86,9 +83,6 @@ public class BaseMigrationTasks<T extends Enum> {
void validate(Collection<BaseTask<?>> theTasks) { void validate(Collection<BaseTask<?>> theTasks) {
for (BaseTask task: theTasks) { for (BaseTask task: theTasks) {
if (task.isLogMessage()) {
continue;
}
task.validateVersion(); task.validateVersion();
String version = task.getFlywayVersion(); String version = task.getFlywayVersion();
MigrationVersion migrationVersion = MigrationVersion.fromVersion(version); MigrationVersion migrationVersion = MigrationVersion.fromVersion(version);

View File

@ -37,9 +37,10 @@ public class Builder {
return this; return this;
} }
// Flyway doesn't support these kinds of migrations
@Deprecated
public Builder startSectionWithMessage(String theMessage) { public Builder startSectionWithMessage(String theMessage) {
Validate.notBlank(theMessage); // Do nothing
addTask(new LogStartSectionWithMessageTask(theMessage));
return this; return this;
} }
@ -214,7 +215,6 @@ public class Builder {
myUnique = theUnique; myUnique = theUnique;
} }
// FIXME KHS find all instances of this. The String... messed up the conversion
public void withColumns(String theVersion, String... theColumnNames) { public void withColumns(String theVersion, String... theColumnNames) {
AddIndexTask task = new AddIndexTask(myRelease, theVersion); AddIndexTask task = new AddIndexTask(myRelease, theVersion);
task.setTableName(myTableName); task.setTableName(myTableName);