diff --git a/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/app/Main.java b/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/app/Main.java index 837c843117e..47c3210b910 100644 --- a/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/app/Main.java +++ b/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/app/Main.java @@ -459,37 +459,38 @@ protected void updateFhirSchema() { buildFhirDataSchemaModel(pdm); boolean isNewDb = updateSchema(pdm); - // If the db is multi-tenant, we populate the resource types and parameter names in allocate-tenant. - // Otherwise, if its a new schema, populate the resource types and parameters names (codes) now - if (!MULTITENANT_FEATURE_ENABLED.contains(dbType) && isNewDb) { - populateResourceTypeAndParameterNameTableEntries(null); - } - - if (MULTITENANT_FEATURE_ENABLED.contains(dbType)) { - logger.info("Refreshing tenant partitions"); - refreshTenants(); - } - - // backfill the resource_change_log table if needed - backfillResourceChangeLog(); - - // perform any updates we need related to the V0010 schema change (IS_DELETED flag) - applyDataMigrationForV0010(); - - // V0014 IS_DELETED and LAST_UPDATED added to whole-system LOGICAL_RESOURCES - applyDataMigrationForV0014(); - - // V0021 removes Abstract Type tables which are unused. - applyTableRemovalForV0021(); - - // Apply privileges if asked - if (grantTo != null) { - grantPrivilegesForFhirData(); + if (this.exitStatus == EXIT_OK) { + // If the db is multi-tenant, we populate the resource types and parameter names in allocate-tenant. + // Otherwise, if its a new schema, populate the resource types and parameters names (codes) now + if (!MULTITENANT_FEATURE_ENABLED.contains(dbType) && isNewDb) { + populateResourceTypeAndParameterNameTableEntries(null); + } + + if (MULTITENANT_FEATURE_ENABLED.contains(dbType)) { + logger.info("Refreshing tenant partitions"); + refreshTenants(); + } + + // backfill the resource_change_log table if needed + backfillResourceChangeLog(); + + // perform any updates we need related to the V0010 schema change (IS_DELETED flag) + applyDataMigrationForV0010(); + + // V0014 IS_DELETED and LAST_UPDATED added to whole-system LOGICAL_RESOURCES + applyDataMigrationForV0014(); + + // V0021 removes Abstract Type tables which are unused. + applyTableRemovalForV0021(); + + // Apply privileges if asked + if (grantTo != null) { + grantPrivilegesForFhirData(); + } + + // Finally, update the whole schema version + svm.updateSchemaVersion(); } - - // Finally, update the whole schema version - svm.updateSchemaVersion(); - } } finally { leaseManager.cancelLease(); @@ -523,13 +524,15 @@ protected void updateOauthSchema() { buildOAuthSchemaModel(pdm); updateSchema(pdm); - // Apply privileges if asked - if (grantTo != null) { - grantPrivilegesForOAuth(); + if (this.exitStatus == EXIT_OK) { + // Apply privileges if asked + if (grantTo != null) { + grantPrivilegesForOAuth(); + } + + // Mark the schema as up-to-date + svm.updateSchemaVersion(); } - - // Mark the schema as up-to-date - svm.updateSchemaVersion(); } } finally { leaseManager.cancelLease(); @@ -562,14 +565,16 @@ protected void updateJavaBatchSchema() { PhysicalDataModel pdm = new PhysicalDataModel(); buildJavaBatchSchemaModel(pdm); updateSchema(pdm); - - // Apply privileges if asked - if (grantTo != null) { - grantPrivilegesForBatch(); + + if (this.exitStatus == EXIT_OK) { + // Apply privileges if asked + if (grantTo != null) { + grantPrivilegesForBatch(); + } + + // Mark the schema as up-to-date + svm.updateSchemaVersion(); } - - // Mark the schema as up-to-date - svm.updateSchemaVersion(); } } finally { leaseManager.cancelLease(); diff --git a/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/FhirSchemaVersion.java b/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/FhirSchemaVersion.java index b215a8de5f3..6f1e2b88a30 100644 --- a/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/FhirSchemaVersion.java +++ b/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/FhirSchemaVersion.java @@ -40,6 +40,7 @@ public enum FhirSchemaVersion { ,V0019(19, "issue-1822 changes per the IBM Cloud Database Team", true) ,V0020(20, "issue-1834 Set PostgreSQL fillfactor", true) ,V0021(21, "issue-713 remove Resource_LOGICAL_RESOURCES, DomainResource_LOGICAL_RESOURCES tables", false) + ,V0022(22, "issue-2979 stored procedure update for 2050 ifNoneMatch", false) ; // The version number recorded in the VERSION_HISTORY diff --git a/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/MigrateV0021AbstractTypeRemoval.java b/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/MigrateV0021AbstractTypeRemoval.java index 295c1b170c2..711bdf61b90 100644 --- a/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/MigrateV0021AbstractTypeRemoval.java +++ b/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/MigrateV0021AbstractTypeRemoval.java @@ -36,6 +36,8 @@ public class MigrateV0021AbstractTypeRemoval implements IDatabaseStatement { private static final Logger LOG = Logger.getLogger(MigrateV0021AbstractTypeRemoval.class.getName()); private static final List VALUE_TYPES = Arrays.asList( + "COMPOSITES", + "TOKEN_VALUES", "RESOURCE_TOKEN_REFS", "DATE_VALUES", "LATLNG_VALUES", @@ -116,15 +118,25 @@ private void checkShouldThrowException() { */ private void cleanupHistory(IDatabaseTranslator translator, Connection c) { // Clean up the Tables and Views and Index for the DomainResource and Resource Table Group. + StringBuilder objectNameInList = new StringBuilder(); + + // It's OK to use literals here because the DEPRECATED_TABLES list is fixed in code + for (String objectName: UnusedTableRemovalNeedsV0021Migration.DEPRECATED_TABLES) { + if (objectNameInList.length() > 0) { + objectNameInList.append(", "); + } + objectNameInList.append("'"); + objectNameInList.append(objectName); + objectNameInList.append("'"); + } final String sql = "DELETE FROM FHIR_ADMIN.VERSION_HISTORY" - + " WHERE (OBJECT_NAME LIKE 'DOMAINRESOURCE_%'" - + " OR OBJECT_NAME LIKE 'RESOURCE_%')" - + " AND SCHEMA_NAME = ?"; + + " WHERE SCHEMA_NAME = ? " + + " AND OBJECT_NAME IN (" + objectNameInList.toString() + ")"; try (PreparedStatement ps = c.prepareStatement(sql)) { ps.setString(1, schemaName); int vhsChanged = ps.executeUpdate(); - LOG.info("VersionHistoryServce: removed =[" + vhsChanged + "]"); + LOG.info("VersionHistoryService: removed =[" + vhsChanged + "]"); } catch (SQLException x) { throw translator.translate(x); } diff --git a/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/UnusedTableRemovalNeedsV0021Migration.java b/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/UnusedTableRemovalNeedsV0021Migration.java index 9038f0702d9..4cb3a690874 100644 --- a/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/UnusedTableRemovalNeedsV0021Migration.java +++ b/fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/UnusedTableRemovalNeedsV0021Migration.java @@ -26,6 +26,7 @@ public class UnusedTableRemovalNeedsV0021Migration implements IDatabaseSupplier< public static final List DEPRECATED_TABLES = Arrays.asList( // DOMAINRESOURCE + "DOMAINRESOURCE_COMPOSITES", "DOMAINRESOURCE_DATE_VALUES", "DOMAINRESOURCE_LATLNG_VALUES", "DOMAINRESOURCE_LOGICAL_RESOURCES", @@ -37,7 +38,9 @@ public class UnusedTableRemovalNeedsV0021Migration implements IDatabaseSupplier< "DOMAINRESOURCE_SECURITY", "DOMAINRESOURCE_STR_VALUES", "DOMAINRESOURCE_TAGS", + "DOMAINRESOURCE_TOKEN_VALUES", // RESOURCE + "RESOURCE_COMPOSITES", "RESOURCE_DATE_VALUES", "RESOURCE_LATLNG_VALUES", "RESOURCE_LOGICAL_RESOURCES", @@ -48,7 +51,9 @@ public class UnusedTableRemovalNeedsV0021Migration implements IDatabaseSupplier< "RESOURCE_RESOURCES", "RESOURCE_SECURITY", "RESOURCE_STR_VALUES", - "RESOURCE_TAGS"); + "RESOURCE_TAGS", + "RESOURCE_TOKEN_VALUES" + ); // Table Count public static final int TABLE_COUNT = DEPRECATED_TABLES.size(); diff --git a/fhir-persistence-schema/src/test/java/com/ibm/fhir/schema/derby/DerbySchemaVersionsTest.java b/fhir-persistence-schema/src/test/java/com/ibm/fhir/schema/derby/DerbySchemaVersionsTest.java index 3a01f97d637..f66ae5ff1cc 100644 --- a/fhir-persistence-schema/src/test/java/com/ibm/fhir/schema/derby/DerbySchemaVersionsTest.java +++ b/fhir-persistence-schema/src/test/java/com/ibm/fhir/schema/derby/DerbySchemaVersionsTest.java @@ -51,7 +51,7 @@ public void test() throws Exception { // Make sure we can correctly determine the latest schema version value svm.updateSchemaVersion(); - assertEquals(svm.getVersionForSchema(), FhirSchemaVersion.V0021.vid()); + assertEquals(svm.getVersionForSchema(), FhirSchemaVersion.V0022.vid()); assertTrue(svm.isLatestSchema()); }