Skip to content

Commit f7d50cc

Browse files
committed
issue 2979 fix schema version tracking regression
Signed-off-by: Robin Arnold <robin.arnold@ibm.com>
1 parent bcf502b commit f7d50cc

4 files changed

Lines changed: 54 additions & 47 deletions

File tree

fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/app/Main.java

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -459,37 +459,38 @@ protected void updateFhirSchema() {
459459
buildFhirDataSchemaModel(pdm);
460460
boolean isNewDb = updateSchema(pdm);
461461

462-
// If the db is multi-tenant, we populate the resource types and parameter names in allocate-tenant.
463-
// Otherwise, if its a new schema, populate the resource types and parameters names (codes) now
464-
if (!MULTITENANT_FEATURE_ENABLED.contains(dbType) && isNewDb) {
465-
populateResourceTypeAndParameterNameTableEntries(null);
466-
}
467-
468-
if (MULTITENANT_FEATURE_ENABLED.contains(dbType)) {
469-
logger.info("Refreshing tenant partitions");
470-
refreshTenants();
471-
}
472-
473-
// backfill the resource_change_log table if needed
474-
backfillResourceChangeLog();
475-
476-
// perform any updates we need related to the V0010 schema change (IS_DELETED flag)
477-
applyDataMigrationForV0010();
478-
479-
// V0014 IS_DELETED and LAST_UPDATED added to whole-system LOGICAL_RESOURCES
480-
applyDataMigrationForV0014();
481-
482-
// V0021 removes Abstract Type tables which are unused.
483-
applyTableRemovalForV0021();
484-
485-
// Apply privileges if asked
486-
if (grantTo != null) {
487-
grantPrivilegesForFhirData();
462+
if (this.exitStatus == EXIT_OK) {
463+
// If the db is multi-tenant, we populate the resource types and parameter names in allocate-tenant.
464+
// Otherwise, if its a new schema, populate the resource types and parameters names (codes) now
465+
if (!MULTITENANT_FEATURE_ENABLED.contains(dbType) && isNewDb) {
466+
populateResourceTypeAndParameterNameTableEntries(null);
467+
}
468+
469+
if (MULTITENANT_FEATURE_ENABLED.contains(dbType)) {
470+
logger.info("Refreshing tenant partitions");
471+
refreshTenants();
472+
}
473+
474+
// backfill the resource_change_log table if needed
475+
backfillResourceChangeLog();
476+
477+
// perform any updates we need related to the V0010 schema change (IS_DELETED flag)
478+
applyDataMigrationForV0010();
479+
480+
// V0014 IS_DELETED and LAST_UPDATED added to whole-system LOGICAL_RESOURCES
481+
applyDataMigrationForV0014();
482+
483+
// V0021 removes Abstract Type tables which are unused.
484+
applyTableRemovalForV0021();
485+
486+
// Apply privileges if asked
487+
if (grantTo != null) {
488+
grantPrivilegesForFhirData();
489+
}
490+
491+
// Finally, update the whole schema version
492+
svm.updateSchemaVersion();
488493
}
489-
490-
// Finally, update the whole schema version
491-
svm.updateSchemaVersion();
492-
493494
}
494495
} finally {
495496
leaseManager.cancelLease();
@@ -523,13 +524,15 @@ protected void updateOauthSchema() {
523524
buildOAuthSchemaModel(pdm);
524525
updateSchema(pdm);
525526

526-
// Apply privileges if asked
527-
if (grantTo != null) {
528-
grantPrivilegesForOAuth();
527+
if (this.exitStatus == EXIT_OK) {
528+
// Apply privileges if asked
529+
if (grantTo != null) {
530+
grantPrivilegesForOAuth();
531+
}
532+
533+
// Mark the schema as up-to-date
534+
svm.updateSchemaVersion();
529535
}
530-
531-
// Mark the schema as up-to-date
532-
svm.updateSchemaVersion();
533536
}
534537
} finally {
535538
leaseManager.cancelLease();
@@ -562,14 +565,16 @@ protected void updateJavaBatchSchema() {
562565
PhysicalDataModel pdm = new PhysicalDataModel();
563566
buildJavaBatchSchemaModel(pdm);
564567
updateSchema(pdm);
565-
566-
// Apply privileges if asked
567-
if (grantTo != null) {
568-
grantPrivilegesForBatch();
568+
569+
if (this.exitStatus == EXIT_OK) {
570+
// Apply privileges if asked
571+
if (grantTo != null) {
572+
grantPrivilegesForBatch();
573+
}
574+
575+
// Mark the schema as up-to-date
576+
svm.updateSchemaVersion();
569577
}
570-
571-
// Mark the schema as up-to-date
572-
svm.updateSchemaVersion();
573578
}
574579
} finally {
575580
leaseManager.cancelLease();

fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/FhirSchemaVersion.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public enum FhirSchemaVersion {
4040
,V0019(19, "issue-1822 changes per the IBM Cloud Database Team", true)
4141
,V0020(20, "issue-1834 Set PostgreSQL fillfactor", true)
4242
,V0021(21, "issue-713 remove Resource_LOGICAL_RESOURCES, DomainResource_LOGICAL_RESOURCES tables", false)
43+
,V0022(22, "issue-2979 stored procedure update for 2050 ifNoneMatch", false)
4344
;
4445

4546
// The version number recorded in the VERSION_HISTORY

fhir-persistence-schema/src/main/java/com/ibm/fhir/schema/control/MigrateV0021AbstractTypeRemoval.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ private void cleanupHistory(IDatabaseTranslator translator, Connection c) {
118118
// Clean up the Tables and Views and Index for the DomainResource and Resource Table Group.
119119
final String sql =
120120
"DELETE FROM FHIR_ADMIN.VERSION_HISTORY"
121-
+ " WHERE (OBJECT_NAME LIKE 'DOMAINRESOURCE_%'"
122-
+ " OR OBJECT_NAME LIKE 'RESOURCE_%')"
123-
+ " AND SCHEMA_NAME = ?";
121+
+ " WHERE (OBJECT_NAME LIKE 'DOMAINRESOURCE_%'"
122+
+ " OR OBJECT_NAME LIKE 'RESOURCE_%')"
123+
+ " AND SCHEMA_NAME = ? "
124+
+ " AND OBJECT_NAME NOT IN ('RESOURCE_TYPES', 'RESOURCE_CHANGE_LOG', 'RESOURCE_TOKEN_REFS')";
124125
try (PreparedStatement ps = c.prepareStatement(sql)) {
125126
ps.setString(1, schemaName);
126127
int vhsChanged = ps.executeUpdate();

fhir-persistence-schema/src/test/java/com/ibm/fhir/schema/derby/DerbySchemaVersionsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void test() throws Exception {
5151

5252
// Make sure we can correctly determine the latest schema version value
5353
svm.updateSchemaVersion();
54-
assertEquals(svm.getVersionForSchema(), FhirSchemaVersion.V0021.vid());
54+
assertEquals(svm.getVersionForSchema(), FhirSchemaVersion.V0022.vid());
5555

5656
assertTrue(svm.isLatestSchema());
5757
}

0 commit comments

Comments
 (0)