From 28e628ec0e49b44c83d608b32ac00925a1715f01 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Tue, 29 Oct 2019 18:03:13 -0400 Subject: [PATCH] all done but reversioning --- .../uhn/fhir/jpa/migrate/FlywayMigrator.java | 4 +- .../taskdef/BaseTableColumnTypeTask.java | 6 ++- .../fhir/jpa/migrate/taskdef/BaseTask.java | 5 -- .../LogStartSectionWithMessageTask.java | 53 ------------------- .../jpa/migrate/taskdef/ModifyColumnTask.java | 11 ++-- .../tasks/HapiFhirJpaMigrationTasks.java | 40 +++++++------- .../migrate/tasks/api/BaseMigrationTasks.java | 6 --- .../fhir/jpa/migrate/tasks/api/Builder.java | 6 +-- 8 files changed, 35 insertions(+), 96 deletions(-) delete mode 100644 hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/LogStartSectionWithMessageTask.java diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/FlywayMigrator.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/FlywayMigrator.java index f5abea3b77f..8d5421b90b6 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/FlywayMigrator.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/FlywayMigrator.java @@ -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) { 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 e841f574b8e..6fc35fa08ef 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 @@ -141,11 +141,15 @@ public abstract class BaseTableColumnTypeTask 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; 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 5b100f2be88..cd18f042a22 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 @@ -180,9 +180,4 @@ public abstract class BaseTask { return myArguments; } } - - // FIXME KHS find a way to put these back in - public boolean isLogMessage() { - return false; - } } diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/LogStartSectionWithMessageTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/LogStartSectionWithMessageTask.java deleted file mode 100644 index 4bf90a70f7d..00000000000 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/LogStartSectionWithMessageTask.java +++ /dev/null @@ -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; - } -} diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTask.java index b4f9e83e7ac..79c8a268dc6 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTask.java @@ -60,21 +60,22 @@ public class ModifyColumnTask extends BaseTableColumnTypeTask 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; 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 187f7da6656..da1c1dd8cac 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 @@ -50,15 +50,15 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { .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 { 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 { } - 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 { } - 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 { 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()); 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 6732766cd9f..bad64f5664c 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 @@ -71,9 +71,6 @@ public class BaseMigrationTasks { public List> getAllTasks(T[] theVersionEnumValues) { List> 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> nextValues = myTasks.get(nextVersion); if (nextValues != null) { validate(nextValues); @@ -86,9 +83,6 @@ public class BaseMigrationTasks { void validate(Collection> theTasks) { for (BaseTask task: theTasks) { - if (task.isLogMessage()) { - continue; - } task.validateVersion(); String version = task.getFlywayVersion(); MigrationVersion migrationVersion = MigrationVersion.fromVersion(version); diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/Builder.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/Builder.java index 7fbb2bcbf31..ae6736846e6 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/Builder.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/Builder.java @@ -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);