Skip to content

Commit f93ed2f

Browse files
authored
Merge pull request #2980 from IBM/issue-2979
issue 2979 fix schema version tracking regression
2 parents e60a334 + 3470c6a commit f93ed2f

5 files changed

Lines changed: 72 additions & 49 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: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public class MigrateV0021AbstractTypeRemoval implements IDatabaseStatement {
3636
private static final Logger LOG = Logger.getLogger(MigrateV0021AbstractTypeRemoval.class.getName());
3737

3838
private static final List<String> VALUE_TYPES = Arrays.asList(
39+
"COMPOSITES",
40+
"TOKEN_VALUES",
3941
"RESOURCE_TOKEN_REFS",
4042
"DATE_VALUES",
4143
"LATLNG_VALUES",
@@ -116,15 +118,25 @@ private void checkShouldThrowException() {
116118
*/
117119
private void cleanupHistory(IDatabaseTranslator translator, Connection c) {
118120
// Clean up the Tables and Views and Index for the DomainResource and Resource Table Group.
121+
StringBuilder objectNameInList = new StringBuilder();
122+
123+
// It's OK to use literals here because the DEPRECATED_TABLES list is fixed in code
124+
for (String objectName: UnusedTableRemovalNeedsV0021Migration.DEPRECATED_TABLES) {
125+
if (objectNameInList.length() > 0) {
126+
objectNameInList.append(", ");
127+
}
128+
objectNameInList.append("'");
129+
objectNameInList.append(objectName);
130+
objectNameInList.append("'");
131+
}
119132
final String sql =
120133
"DELETE FROM FHIR_ADMIN.VERSION_HISTORY"
121-
+ " WHERE (OBJECT_NAME LIKE 'DOMAINRESOURCE_%'"
122-
+ " OR OBJECT_NAME LIKE 'RESOURCE_%')"
123-
+ " AND SCHEMA_NAME = ?";
134+
+ " WHERE SCHEMA_NAME = ? "
135+
+ " AND OBJECT_NAME IN (" + objectNameInList.toString() + ")";
124136
try (PreparedStatement ps = c.prepareStatement(sql)) {
125137
ps.setString(1, schemaName);
126138
int vhsChanged = ps.executeUpdate();
127-
LOG.info("VersionHistoryServce: removed =[" + vhsChanged + "]");
139+
LOG.info("VersionHistoryService: removed =[" + vhsChanged + "]");
128140
} catch (SQLException x) {
129141
throw translator.translate(x);
130142
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class UnusedTableRemovalNeedsV0021Migration implements IDatabaseSupplier<
2626
public static final List<String> DEPRECATED_TABLES =
2727
Arrays.asList(
2828
// DOMAINRESOURCE
29+
"DOMAINRESOURCE_COMPOSITES",
2930
"DOMAINRESOURCE_DATE_VALUES",
3031
"DOMAINRESOURCE_LATLNG_VALUES",
3132
"DOMAINRESOURCE_LOGICAL_RESOURCES",
@@ -37,7 +38,9 @@ public class UnusedTableRemovalNeedsV0021Migration implements IDatabaseSupplier<
3738
"DOMAINRESOURCE_SECURITY",
3839
"DOMAINRESOURCE_STR_VALUES",
3940
"DOMAINRESOURCE_TAGS",
41+
"DOMAINRESOURCE_TOKEN_VALUES",
4042
// RESOURCE
43+
"RESOURCE_COMPOSITES",
4144
"RESOURCE_DATE_VALUES",
4245
"RESOURCE_LATLNG_VALUES",
4346
"RESOURCE_LOGICAL_RESOURCES",
@@ -48,7 +51,9 @@ public class UnusedTableRemovalNeedsV0021Migration implements IDatabaseSupplier<
4851
"RESOURCE_RESOURCES",
4952
"RESOURCE_SECURITY",
5053
"RESOURCE_STR_VALUES",
51-
"RESOURCE_TAGS");
54+
"RESOURCE_TAGS",
55+
"RESOURCE_TOKEN_VALUES"
56+
);
5257

5358
// Table Count
5459
public static final int TABLE_COUNT = DEPRECATED_TABLES.size();

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)