diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java index 0006487dc7a..83da79122fc 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersion.java @@ -31,12 +31,10 @@ import java.util.Collection; import static org.apache.commons.lang3.StringUtils.length; -//@formatter:off @Table(name = "TRM_CODESYSTEM_VER" // Note, we used to have a constraint named IDX_CSV_RESOURCEPID_AND_VER (don't reuse this) ) @Entity() -//@formatter:on public class TermCodeSystemVersion implements Serializable { private static final long serialVersionUID = 1L; 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 94b0b30ce1a..c5cb793b61d 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 @@ -95,6 +95,13 @@ public abstract class BaseTableColumnTypeTask extends B setColumnType(ColumnTypeEnum.BLOB, DriverTypeEnum.POSTGRES_9_4, "oid"); setColumnType(ColumnTypeEnum.BLOB, DriverTypeEnum.MSSQL_2012, "varbinary(MAX)"); + setColumnType(ColumnTypeEnum.CLOB, DriverTypeEnum.H2_EMBEDDED, "clob"); + setColumnType(ColumnTypeEnum.CLOB, DriverTypeEnum.DERBY_EMBEDDED, "clob(100000)"); + setColumnType(ColumnTypeEnum.CLOB, DriverTypeEnum.MARIADB_10_1, "longtext"); + setColumnType(ColumnTypeEnum.CLOB, DriverTypeEnum.MYSQL_5_7, "longtext"); + setColumnType(ColumnTypeEnum.CLOB, DriverTypeEnum.ORACLE_12C, "clob"); + setColumnType(ColumnTypeEnum.CLOB, DriverTypeEnum.POSTGRES_9_4, "text"); + setColumnType(ColumnTypeEnum.CLOB, DriverTypeEnum.MSSQL_2012, "varchar(MAX)"); } public ColumnTypeEnum getColumnType() { @@ -214,8 +221,15 @@ public abstract class BaseTableColumnTypeTask extends B Assert.isTrue(theColumnLength == null, "Must not supply a column length"); return "blob"; } - }; + }, + CLOB { + @Override + public String getDescriptor(Long theColumnLength) { + Assert.isTrue(theColumnLength == null, "Must not supply a column length"); + return "clob"; + } + }; public abstract String getDescriptor(Long theColumnLength); diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIdGeneratorTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIdGeneratorTask.java new file mode 100644 index 00000000000..6ef1960e0cc --- /dev/null +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIdGeneratorTask.java @@ -0,0 +1,101 @@ +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 ca.uhn.fhir.jpa.migrate.JdbcUtils; +import org.apache.commons.lang3.Validate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.SQLException; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.apache.commons.lang3.StringUtils.isNotBlank; + +public class DropIdGeneratorTask extends BaseTask { + + private static final Logger ourLog = LoggerFactory.getLogger(DropIdGeneratorTask.class); + private final String myGeneratorName; + + public DropIdGeneratorTask(String theGeneratorName) { + myGeneratorName = theGeneratorName; + } + + @Override + public void validate() { + Validate.notBlank(myGeneratorName); + } + + @Override + public void execute() throws SQLException { + Set tableNames = JdbcUtils.getTableNames(getConnectionProperties()); + String sql = null; + + switch (getDriverType()) { + case MARIADB_10_1: + case MYSQL_5_7: + // These require a separate table + if (tableNames.contains(myGeneratorName)) { + + String initSql = "delete from " + myGeneratorName; + executeSql(myGeneratorName, initSql); + + String creationSql = "drop table " + myGeneratorName; + executeSql(myGeneratorName, creationSql); + + } + break; + case DERBY_EMBEDDED: + case H2_EMBEDDED: + sql = "drop sequence " + myGeneratorName; + break; + case POSTGRES_9_4: + sql = "drop sequence " + myGeneratorName; + break; + case ORACLE_12C: + sql = "drop sequence " + myGeneratorName; + break; + case MSSQL_2012: + sql = "drop sequence " + myGeneratorName; + break; + default: + throw new IllegalStateException(); + } + + if (isNotBlank(sql)) { + Set sequenceNames = + JdbcUtils.getSequenceNames(getConnectionProperties()) + .stream() + .map(String::toLowerCase) + .collect(Collectors.toSet()); + ourLog.debug("Currently have sequences: {}", sequenceNames); + if (!sequenceNames.contains(myGeneratorName.toLowerCase())) { + ourLog.info("Sequence {} does not exist - No action performed", myGeneratorName); + return; + } + + executeSql(myGeneratorName, sql); + } + + } + +} 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 5574be04e90..851fbac8694 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 @@ -93,6 +93,10 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { Builder.BuilderWithTableName termValueSetTable = version.onTable("TRM_VALUESET"); termValueSetTable.addColumn("TOTAL_CONCEPTS").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); termValueSetTable.addColumn("TOTAL_CONCEPT_DESIGNATIONS").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + termValueSetTable + .dropIndex("IDX_VALUESET_EXP_STATUS"); + + version.dropIdGenerator("SEQ_SEARCHPARM_ID"); } protected void init400() { @@ -115,22 +119,54 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { .renameColumn("myConceptMapUrl", "CONCEPT_MAP_URL", false, true) .renameColumn("mySourceValueSet", "SOURCE_VS", false, true) .renameColumn("myTargetValueSet", "TARGET_VS", false, true); + version.onTable("TRM_CONCEPT_MAP_GROUP") + .modifyColumn("CONCEPT_MAP_URL").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + version.onTable("TRM_CONCEPT_MAP_GROUP") + .modifyColumn("SOURCE_VERSION").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + version.onTable("TRM_CONCEPT_MAP_GROUP") + .modifyColumn("SOURCE_VS").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + version.onTable("TRM_CONCEPT_MAP_GROUP") + .modifyColumn("TARGET_VERSION").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + version.onTable("TRM_CONCEPT_MAP_GROUP") + .modifyColumn("TARGET_VS").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); version.onTable("TRM_CONCEPT_MAP_GRP_ELEMENT") .renameColumn("myConceptMapUrl", "CONCEPT_MAP_URL", false, true) .renameColumn("mySystem", "SYSTEM_URL", false, true) .renameColumn("mySystemVersion", "SYSTEM_VERSION", false, true) .renameColumn("myValueSet", "VALUESET_URL", false, true); + version.onTable("TRM_CONCEPT_MAP_GRP_ELEMENT") + .modifyColumn("CONCEPT_MAP_URL").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + version.onTable("TRM_CONCEPT_MAP_GRP_ELEMENT") + .modifyColumn("SOURCE_CODE").nonNullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 500); + version.onTable("TRM_CONCEPT_MAP_GRP_ELEMENT") + .modifyColumn("SYSTEM_URL").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + version.onTable("TRM_CONCEPT_MAP_GRP_ELEMENT") + .modifyColumn("SYSTEM_VERSION").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + version.onTable("TRM_CONCEPT_MAP_GRP_ELEMENT") + .modifyColumn("VALUESET_URL").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); version.onTable("TRM_CONCEPT_MAP_GRP_ELM_TGT") .renameColumn("myConceptMapUrl", "CONCEPT_MAP_URL", false, true) .renameColumn("mySystem", "SYSTEM_URL", false, true) .renameColumn("mySystemVersion", "SYSTEM_VERSION", false, true) .renameColumn("myValueSet", "VALUESET_URL", false, true); + version.onTable("TRM_CONCEPT_MAP_GRP_ELM_TGT") + .modifyColumn("CONCEPT_MAP_URL").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + version.onTable("TRM_CONCEPT_MAP_GRP_ELM_TGT") + .modifyColumn("SYSTEM_URL").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + version.onTable("TRM_CONCEPT_MAP_GRP_ELM_TGT") + .modifyColumn("SYSTEM_VERSION").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + version.onTable("TRM_CONCEPT_MAP_GRP_ELM_TGT") + .modifyColumn("TARGET_CODE").nonNullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 500); + version.onTable("TRM_CONCEPT_MAP_GRP_ELM_TGT") + .modifyColumn("VALUESET_URL").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); version.onTable("TRM_CONCEPT") .renameColumn("CODE", "CODEVAL", false, true); + + // TermValueSet version.startSectionWithMessage("Processing table: TRM_VALUESET"); version.addIdGenerator("SEQ_VALUESET_PID"); @@ -150,6 +186,8 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { version.onTable("TRM_VALUESET") .renameColumn("NAME", "VSNAME", true, true); + version.onTable("TRM_VALUESET") + .modifyColumn("RES_ID").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); Builder.BuilderWithTableName termValueSetTableChange = version.onTable("TRM_VALUESET"); termValueSetTableChange.addColumn("EXPANSION_STATUS").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, TermValueSet.MAX_EXPANSION_STATUS_LENGTH); @@ -206,6 +244,47 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { version.startSectionWithMessage("Processing table: TRM_CODESYSTEM_VER"); Builder.BuilderWithTableName termCodeSystemVersionTable = version.onTable("TRM_CODESYSTEM_VER"); termCodeSystemVersionTable.addColumn("CS_DISPLAY").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, TermCodeSystemVersion.MAX_VERSION_LENGTH); + + // ResourceReindexJobEntry + version.addIdGenerator("SEQ_RES_REINDEX_JOB"); + Builder.BuilderAddTableByColumns reindex = version.addTableByColumns("HFJ_RES_REINDEX_JOB", "PID"); + reindex.addColumn("PID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + reindex.addColumn("RES_TYPE").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, Constants.MAX_RESOURCE_NAME_LENGTH); + reindex.addColumn("UPDATE_THRESHOLD_HIGH").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.DATE_TIMESTAMP); + reindex.addColumn("JOB_DELETED").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.BOOLEAN); + reindex.addColumn("UPDATE_THRESHOLD_LOW").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.DATE_TIMESTAMP); + reindex.addColumn("SUSPENDED_UNTIL").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.DATE_TIMESTAMP); + reindex.addColumn("REINDEX_COUNT").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.INT); + + // Search + version.onTable("HFJ_SEARCH") + .addColumn("SEARCH_DELETED").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.BOOLEAN); + version.onTable("HFJ_SEARCH") + .modifyColumn("SEARCH_LAST_RETURNED").nonNullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.DATE_TIMESTAMP); + version.onTable("HFJ_SEARCH") + .addColumn("SEARCH_PARAM_MAP").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.BLOB); + version.onTable("HFJ_SEARCH") + .modifyColumn("SEARCH_UUID").nonNullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, Search.UUID_COLUMN_LENGTH); + + version.onTable("HFJ_SEARCH_PARM").dropThisTable(); + + version.onTable("HFJ_SPIDX_COORDS").modifyColumn("RES_TYPE").nonNullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 100); + version.onTable("HFJ_SPIDX_DATE").modifyColumn("RES_TYPE").nonNullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 100); + version.onTable("HFJ_SPIDX_STRING").modifyColumn("RES_TYPE").nonNullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 100); + version.onTable("HFJ_SPIDX_STRING").addColumn("HASH_IDENTITY").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + version.onTable("HFJ_SPIDX_STRING").addIndex("IDX_SP_STRING_HASH_IDENT").unique(false).withColumns("HASH_IDENTITY"); + version.onTable("HFJ_SPIDX_COORDS").modifyColumn("RES_TYPE").nonNullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 100); + version.onTable("HFJ_SPIDX_QUANTITY").modifyColumn("RES_TYPE").nonNullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 100); + version.onTable("HFJ_SPIDX_QUANTITY").dropColumn("HASH_UNITS_AND_VALPREFIX"); + version.onTable("HFJ_SPIDX_QUANTITY").dropColumn("HASH_VALPREFIX"); + version.onTable("HFJ_SPIDX_NUMBER").modifyColumn("RES_TYPE").nonNullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 100); + version.onTable("HFJ_SPIDX_TOKEN").modifyColumn("RES_TYPE").nonNullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 100); + version.onTable("HFJ_SPIDX_URI").modifyColumn("RES_TYPE").nonNullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 100); + version.onTable("HFJ_SPIDX_URI").modifyColumn("SP_URI").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 254); + + version.onTable("TRM_CODESYSTEM").modifyColumn("CODE_SYSTEM_URI").nonNullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + version.onTable("TRM_CODESYSTEM").modifyColumn("CS_NAME").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + version.onTable("TRM_CODESYSTEM_VER").modifyColumn("CS_VERSION_ID").nullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); } @@ -236,6 +315,14 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { .addSql(DriverTypeEnum.MYSQL_5_7, " create table HFJ_RES_REINDEX_JOB (PID bigint not null, JOB_DELETED bit not null, RES_TYPE varchar(255), SUSPENDED_UNTIL datetime(6), UPDATE_THRESHOLD_HIGH datetime(6) not null, UPDATE_THRESHOLD_LOW datetime(6), primary key (PID))") .addSql(DriverTypeEnum.ORACLE_12C, "create table HFJ_RES_REINDEX_JOB (PID number(19,0) not null, JOB_DELETED number(1,0) not null, RES_TYPE varchar2(255 char), SUSPENDED_UNTIL timestamp, UPDATE_THRESHOLD_HIGH timestamp not null, UPDATE_THRESHOLD_LOW timestamp, primary key (PID))"); + version.onTable("TRM_CONCEPT_DESIG").addColumn("CS_VER_PID").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + version.onTable("TRM_CONCEPT_DESIG").addForeignKey("FK_CONCEPTDESIG_CSV").toColumn("CS_VER_PID").references("TRM_CODESYSTEM_VER", "PID"); + + version.onTable("TRM_CONCEPT_PROPERTY").addColumn("CS_VER_PID").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + version.onTable("TRM_CONCEPT_PROPERTY").addForeignKey("FK_CONCEPTPROP_CSV").toColumn("CS_VER_PID").references("TRM_CODESYSTEM_VER", "PID"); + + version.onTable("TRM_CONCEPT").addColumn("PARENT_PIDS").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.CLOB); + } private void init350() { @@ -290,6 +377,8 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { .addIndex("IDX_SP_DATE_HASH") .unique(false) .withColumns("HASH_IDENTITY", "SP_VALUE_LOW", "SP_VALUE_HIGH"); + spidxDate + .dropIndex("IDX_SP_DATE"); spidxDate .addTask(new CalculateHashesTask() .setColumnName("HASH_IDENTITY") @@ -522,6 +611,9 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { version.startSectionWithMessage("Starting work on table: TRM_CONCEPT_DESIG"); version .addTableRawSql("TRM_CONCEPT_DESIG") + .addSql(DriverTypeEnum.H2_EMBEDDED, "create table TRM_CONCEPT_DESIG (PID bigint not null, LANG varchar(500), USE_CODE varchar(500), USE_DISPLAY varchar(500), USE_SYSTEM varchar(500), VAL varchar(500) not null, CS_VER_PID bigint, CONCEPT_PID bigint, primary key (PID))") + .addSql(DriverTypeEnum.H2_EMBEDDED, "alter table TRM_CONCEPT_DESIG add constraint FK_CONCEPTDESIG_CSV foreign key (CS_VER_PID) references TRM_CODESYSTEM_VER") + .addSql(DriverTypeEnum.H2_EMBEDDED, "alter table TRM_CONCEPT_DESIG add constraint FK_CONCEPTDESIG_CONCEPT foreign key (CONCEPT_PID) references TRM_CONCEPT") .addSql(DriverTypeEnum.DERBY_EMBEDDED, "create table TRM_CONCEPT_DESIG (PID bigint not null, LANG varchar(500), USE_CODE varchar(500), USE_DISPLAY varchar(500), USE_SYSTEM varchar(500), VAL varchar(500) not null, CS_VER_PID bigint, CONCEPT_PID bigint, primary key (PID))") .addSql(DriverTypeEnum.DERBY_EMBEDDED, "alter table TRM_CONCEPT_DESIG add constraint FK_CONCEPTDESIG_CSV foreign key (CS_VER_PID) references TRM_CODESYSTEM_VER") .addSql(DriverTypeEnum.DERBY_EMBEDDED, "alter table TRM_CONCEPT_DESIG add constraint FK_CONCEPTDESIG_CONCEPT foreign key (CONCEPT_PID) references TRM_CONCEPT") @@ -649,6 +741,10 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { .addSql(DriverTypeEnum.MSSQL_2012, "create table TRM_CONCEPT_MAP_GRP_ELM_TGT (PID bigint not null, TARGET_CODE varchar(500) not null, myConceptMapUrl varchar(255), TARGET_DISPLAY varchar(400), TARGET_EQUIVALENCE varchar(50), mySystem varchar(255), mySystemVersion varchar(255), myValueSet varchar(255), CONCEPT_MAP_GRP_ELM_PID bigint not null, primary key (PID))") .addSql(DriverTypeEnum.MSSQL_2012, "create index IDX_CNCPT_MP_GRP_ELM_TGT_CD on TRM_CONCEPT_MAP_GRP_ELM_TGT (TARGET_CODE)") .addSql(DriverTypeEnum.MSSQL_2012, "alter table TRM_CONCEPT_MAP_GRP_ELM_TGT add constraint FK_TCMGETARGET_ELEMENT foreign key (CONCEPT_MAP_GRP_ELM_PID) references TRM_CONCEPT_MAP_GRP_ELEMENT"); + + version.onTable("HFJ_IDX_CMP_STRING_UNIQ").modifyColumn("IDX_STRING").nonNullable().withType(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + + } private Boolean columnToBoolean(Object theValue) { 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 cf9fc105ed7..6681a208cea 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 @@ -117,6 +117,11 @@ public class BaseMigrationTasks { addTask(task); } + public void dropIdGenerator(String theIdGeneratorName) { + DropIdGeneratorTask task = new DropIdGeneratorTask(theIdGeneratorName); + addTask(task); + } + public class BuilderAddTableRawSql { private final AddTableRawSqlTask myTask; diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIdGeneratorTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIdGeneratorTaskTest.java new file mode 100644 index 00000000000..b7fd7ed6927 --- /dev/null +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIdGeneratorTaskTest.java @@ -0,0 +1,41 @@ +package ca.uhn.fhir.jpa.migrate.taskdef; + +import ca.uhn.fhir.jpa.migrate.JdbcUtils; +import ca.uhn.fhir.jpa.migrate.tasks.api.BaseMigrationTasks; +import ca.uhn.fhir.util.VersionEnum; +import org.junit.Test; + +import java.sql.SQLException; + +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.junit.Assert.assertThat; + +public class DropIdGeneratorTaskTest extends BaseTest { + + + @Test + public void testAddIdGenerator() throws SQLException { + executeSql("create sequence SEQ_FOO start with 1 increment by 50"); + assertThat(JdbcUtils.getSequenceNames(getConnectionProperties()), containsInAnyOrder("SEQ_FOO")); + + MyMigrationTasks migrator = new MyMigrationTasks(); + getMigrator().addTasks(migrator.getTasks(VersionEnum.V3_3_0, VersionEnum.V3_6_0)); + getMigrator().migrate(); + + assertThat(JdbcUtils.getSequenceNames(getConnectionProperties()), empty()); + } + + + + private static class MyMigrationTasks extends BaseMigrationTasks { + + public MyMigrationTasks() { + Builder v = forVersion(VersionEnum.V3_5_0); + v.dropIdGenerator("SEQ_FOO"); + } + + + } + +}