Fix tag db migration (#3578)

* Fix tag db migration

PG doesn't support drop index online

* changelog
This commit is contained in:
michaelabuckley 2022-05-02 17:59:07 -04:00 committed by GitHub
parent 3a7ea64a40
commit d6702f956b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -0,0 +1,4 @@
---
type: fix
issue: 3578
title: "The tag index migration failed on Postres and Oracle. These have been fixed."

View File

@ -345,9 +345,9 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
.addIndex("20220429.2", "IDX_RES_TAG_TAG_RES")
.unique(false)
.online(true)
.withColumns("RES_ID", "TAG_ID", "PARTITION_ID");
.withColumns("TAG_ID", "RES_ID", "PARTITION_ID");
resTagTable.dropIndexOnline("20220429.4", "IDX_RESTAG_TAGID");
resTagTable.dropIndex("20220429.4", "IDX_RESTAG_TAGID");
// Weird that we don't have addConstraint. No time to do it today.
Map<DriverTypeEnum, String> addResTagConstraint = new HashMap<>();
addResTagConstraint.put(DriverTypeEnum.H2_EMBEDDED, "ALTER TABLE HFJ_RES_TAG ADD CONSTRAINT IDX_RESTAG_TAGID UNIQUE (RES_ID, TAG_ID)");
@ -365,8 +365,9 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
.online(false)
.withColumns("TAG_TYPE", "TAG_CODE", "TAG_SYSTEM", "TAG_ID");
// move constraint to new index
// note the constraint has fewer columns than the index. But these engines can enforce a constraint narrower than the index.
tagTable.dropIndexOnline("20220429.8", "IDX_TAGDEF_TYPESYSCODE");
// Ugh. Only oracle supports using IDX_TAG_DEF_TP_CD_SYS to enforce this constraint. The others will create another index.
// For Sql Server, should change the index to be unique with include columns. Do this in 6.1
tagTable.dropIndex("20220429.8", "IDX_TAGDEF_TYPESYSCODE");
Map<DriverTypeEnum, String> addTagDefConstraint = new HashMap<>();
addTagDefConstraint.put(DriverTypeEnum.H2_EMBEDDED, "ALTER TABLE HFJ_TAG_DEF ADD CONSTRAINT IDX_TAGDEF_TYPESYSCODE UNIQUE (TAG_TYPE, TAG_CODE, TAG_SYSTEM)");
addTagDefConstraint.put(DriverTypeEnum.MARIADB_10_1, "ALTER TABLE HFJ_TAG_DEF ADD CONSTRAINT IDX_TAGDEF_TYPESYSCODE UNIQUE (TAG_TYPE, TAG_CODE, TAG_SYSTEM)");