From a2521f23f166e8598f17462c66f2ff5010c4c820 Mon Sep 17 00:00:00 2001 From: Paul Bastide Date: Mon, 8 Nov 2021 11:31:51 -0500 Subject: [PATCH] Update for lowercase names Signed-off-by: Paul Bastide --- .../MigrateV0021AbstractTypeRemoval.java | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) 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 9a0f4d79811..295c1b170c2 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 @@ -158,25 +158,30 @@ private void checkDataInAllPartitionedTenantTables(IDatabaseTranslator translato */ private void checkDataTables(IDatabaseTranslator translator, Connection c) { for (String deprecatedTable : UnusedTableRemovalNeedsV0021Migration.DEPRECATED_TABLES) { - final String table = schemaName + "." + deprecatedTable; + if (adapter.doesTableExist(schemaName, deprecatedTable)) { + String table = schemaName + "." + deprecatedTable; + if (translator.getType() == DbType.POSTGRESQL) { + table = schemaName.toLowerCase() + "." + deprecatedTable; + } - // When checking for data... SYSCAT.TABLES->CARD was considered to be checked. - // However if the db hasn't collected statistics -1 is returned, and unreliable - // Instead we're going to check if it has at least one row... - final String sql = "SELECT * FROM " + table + " " + translator.limit("1"); - try (PreparedStatement ps = c.prepareStatement(sql)) { - if (ps.execute()) { - ResultSet rs = ps.getResultSet(); - if (rs.next()) { - LOG.warning("Data Table contains data '" + table + "'"); - count++; + // When checking for data... SYSCAT.TABLES->CARD was considered to be checked. + // However if the db hasn't collected statistics -1 is returned, and unreliable + // Instead we're going to check if it has at least one row... + final String sql = "SELECT * FROM " + table + " " + translator.limit("1"); + try (PreparedStatement ps = c.prepareStatement(sql)) { + if (ps.execute()) { + ResultSet rs = ps.getResultSet(); + if (rs.next()) { + LOG.warning("Data Table contains data '" + table + "'"); + count++; + } + } + } catch (SQLException x) { + if (!translator.isUndefinedName(x)){ + throw translator.translate(x); + } else { + LOG.finest("Table already deleted: " + table); } - } - } catch (SQLException x) { - if (!translator.isUndefinedName(x)){ - throw translator.translate(x); - } else { - LOG.finest("Table already deleted: " + table); } } }