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,9 +66,7 @@ public class FlywayMigrator {
}
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) {

View File

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

View File

@ -180,9 +180,4 @@ public abstract class BaseTask<T extends BaseTask> {
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);
}
if (getColumnLength() != null && isNoColumnShrink()) {
Long columnLength = getColumnLength();
if (columnLength != null && isNoColumnShrink()) {
long existingLength = existingType.getLength() != null ? existingType.getLength() : 0;
if (existingLength > getColumnLength()) {
setColumnLength(existingLength);
if (existingLength > columnLength) {
columnLength = existingLength;
}
}
boolean alreadyOfCorrectType = existingType.equals(getColumnType(), getColumnLength());
boolean alreadyOfCorrectType = existingType.equals(getColumnType(), columnLength);
boolean alreadyCorrectNullable = isNullable() == nullable;
if (alreadyOfCorrectType && alreadyCorrectNullable) {
ourLog.info("Column {} on table {} is already of type {} and has nullable {} - No action performed", getColumnName(), getTableName(), existingType, nullable);
return;
}
String type = getSqlType();
String type = getSqlType(columnLength);
String notNull = getSqlNotNull();
String sql = null;

View File

@ -50,15 +50,15 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
.map(FlagEnum::fromCommandLineValue)
.collect(Collectors.toSet());
init330();
init340();
init350();
init360();
init400();
init410();
init330(); // 20180114 - 20180329
init340(); // 20180401 - 20180528
init350(); // 20180601 - 20180917
init360(); // 20180918 - 20181112
init400(); // 20190401 - 20190814
init410(); // 20190815 - present
}
protected void init410() {
protected void init410() { // 20190815 - present
Builder version = forVersion(VersionEnum.V4_1_0);
// 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);
}
protected void init400() {
protected void init400() { // 20190401 - 20190814
Builder version = forVersion(VersionEnum.V4_0_0);
// 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);
// 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);
// Forced ID changes
@ -831,47 +831,47 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
return longValue == 1L;
}
private void init340() {
private void init340() { // 20180401 - 20180528
Builder version = forVersion(VersionEnum.V3_4_0);
// CodeSystem Version
Builder.BuilderWithTableName resourceLink = version.onTable("TRM_CODESYSTEM_VER");
version.startSectionWithMessage("Starting work on table: " + resourceLink.getTableName());
resourceLink
.dropIndex("20180929.1", "IDX_CSV_RESOURCEPID_AND_VER");
.dropIndex("20180401.1", "IDX_CSV_RESOURCEPID_AND_VER");
resourceLink
.dropColumn("20180929.2", "RES_VERSION_ID");
.dropColumn("20180401.2", "RES_VERSION_ID");
resourceLink
.addColumn("20180929.3", "CS_VERSION_ID")
.addColumn("20180401.3", "CS_VERSION_ID")
.nullable()
.type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 255);
resourceLink
.addColumn("20180929.4", "CODESYSTEM_PID")
.addColumn("20180401.4", "CODESYSTEM_PID")
.nullable()
.type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG);
resourceLink
.addForeignKey("FK_CODESYSVER_CS_ID")
.toColumn("CODESYSTEM_PID")
.references("20180929.5", "TRM_CODESYSTEM", "PID");
.references("20180401.5", "TRM_CODESYSTEM", "PID");
// Concept
Builder.BuilderWithTableName concept = version.onTable("TRM_CONCEPT");
version.startSectionWithMessage("Starting work on table: " + concept.getTableName());
concept
.addColumn("20180929.6", "CODE_SEQUENCE")
.addColumn("20180401.6", "CODE_SEQUENCE")
.nullable()
.type(BaseTableColumnTypeTask.ColumnTypeEnum.INT);
}
private void init330() {
private void init330() { // 20180114 - 20180329
Builder version = forVersion(VersionEnum.V3_3_0);
Builder.BuilderWithTableName hfjResource = version.onTable("HFJ_RESOURCE");
version.startSectionWithMessage("Starting work on table: " + hfjResource.getTableName());
hfjResource.dropColumn("20180601.1", "RES_TEXT");
hfjResource.dropColumn("20180601.2", "RES_ENCODING");
hfjResource.dropColumn("20180114.1", "RES_TEXT");
hfjResource.dropColumn("20180114.2", "RES_ENCODING");
Builder.BuilderWithTableName hfjResVer = version.onTable("HFJ_RES_VER");
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) {
List<BaseTask<?>> retval = new ArrayList<>();
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);
if (nextValues != null) {
validate(nextValues);
@ -86,9 +83,6 @@ public class BaseMigrationTasks<T extends Enum> {
void validate(Collection<BaseTask<?>> theTasks) {
for (BaseTask task: theTasks) {
if (task.isLogMessage()) {
continue;
}
task.validateVersion();
String version = task.getFlywayVersion();
MigrationVersion migrationVersion = MigrationVersion.fromVersion(version);

View File

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