Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Comment thread
prb112 marked this conversation as resolved.
}

// Mark the schema as up-to-date
svm.updateSchemaVersion();
}
} finally {
leaseManager.cancelLease();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class MigrateV0021AbstractTypeRemoval implements IDatabaseStatement {
private static final Logger LOG = Logger.getLogger(MigrateV0021AbstractTypeRemoval.class.getName());

private static final List<String> VALUE_TYPES = Arrays.asList(
"COMPOSITES",
"TOKEN_VALUES",
"RESOURCE_TOKEN_REFS",
"DATE_VALUES",
"LATLNG_VALUES",
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class UnusedTableRemovalNeedsV0021Migration implements IDatabaseSupplier<
public static final List<String> DEPRECATED_TABLES =
Arrays.asList(
// DOMAINRESOURCE
"DOMAINRESOURCE_COMPOSITES",
"DOMAINRESOURCE_DATE_VALUES",
"DOMAINRESOURCE_LATLNG_VALUES",
"DOMAINRESOURCE_LOGICAL_RESOURCES",
Expand All @@ -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",
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down