Skip to content

Commit 26dbab4

Browse files
authored
Handle Lowercase PK Column Names (#7174)
* Handle lowercase PK column names * Add changelog
1 parent 00b1618 commit 26dbab4

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
type: fix
3+
issue: 7174
4+
title: "A bug in the SQL validation logic meant that databases which are configured to
5+
use lowercased identifiers incorrectly reported a database partition mode schema when
6+
that setting was not in use (HAPI-2563). This has been corected."

hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/util/PartitionedIdModeVerificationSvcTest.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,26 @@ class PartitionedIdModeVerificationSvcTest {
3030

3131
private static final String MIGRATION_TABLE_NAME = "hapi_migrator";
3232

33-
private DriverTypeEnum.ConnectionProperties myConnectionProperties = newConnection();
33+
private DriverTypeEnum.ConnectionProperties myConnectionProperties;
3434

3535
@Mock
3636
private HibernatePropertiesProvider myHibernatePropertiesProvider;
3737

3838
@ParameterizedTest
39-
@CsvSource({
40-
"true, true",
41-
"true, false",
42-
"false, true",
43-
"false, false"
44-
})
45-
void testPartitionedIdDatabase_WantPartitionedIdDatabase(boolean thePartitionedIdModeForSchema, boolean thePartitionedIdModeForSettings) {
39+
@CsvSource(textBlock =
40+
// Partitioned Schema, Partitioned Settings, Uppercase Identifiers
41+
"""
42+
true, true, true
43+
true, false, true
44+
false, true, true
45+
false, false, true
46+
true, true, false
47+
false, false, false
48+
"""
49+
)
50+
void testPartitionedIdDatabase_WantPartitionedIdDatabase(boolean thePartitionedIdModeForSchema, boolean thePartitionedIdModeForSettings, boolean theCapitalizedIdentifers) {
51+
myConnectionProperties = newConnection(theCapitalizedIdentifers);
52+
4653
Set<String> commandLineValue = thePartitionedIdModeForSchema ? Set.of(HapiFhirJpaMigrationTasks.FlagEnum.DB_PARTITION_MODE.getCommandLineValue()) : Set.of();
4754
HapiFhirJpaMigrationTasks tasks = new HapiFhirJpaMigrationTasks(commandLineValue);
4855

@@ -73,6 +80,8 @@ void testPartitionedIdDatabase_WantPartitionedIdDatabase(boolean thePartitionedI
7380
*/
7481
@Test
7582
void testEmptyDatabaseDoesNotFail() {
83+
myConnectionProperties = newConnection(true);
84+
7685
PlatformTransactionManager txManager = new DataSourceTransactionManager(myConnectionProperties.getDataSource());
7786
when(myHibernatePropertiesProvider.getDataSource()).thenReturn(myConnectionProperties.getDataSource());
7887
when(myHibernatePropertiesProvider.getDialect()).thenReturn(new HapiFhirH2Dialect());
@@ -86,8 +95,15 @@ void testEmptyDatabaseDoesNotFail() {
8695
/**
8796
* Create a new connection to a randomized H2 database for testing
8897
*/
89-
private DriverTypeEnum.ConnectionProperties newConnection() {
90-
String url = "jdbc:h2:mem:test_migration-" + UUID.randomUUID() + ";CASE_INSENSITIVE_IDENTIFIERS=TRUE;";
98+
private DriverTypeEnum.ConnectionProperties newConnection(boolean theCapitalizedIdentifiers) {
99+
String url = "jdbc:h2:mem:test_migration-" + UUID.randomUUID();
100+
if (theCapitalizedIdentifiers) {
101+
url += ";CASE_INSENSITIVE_IDENTIFIERS=TRUE;DATABASE_TO_UPPER=TRUE;DATABASE_TO_LOWER=FALSE;";
102+
} else {
103+
url += ";CASE_INSENSITIVE_IDENTIFIERS=TRUE;DATABASE_TO_LOWER=TRUE;DATABASE_TO_UPPER=FALSE;";
104+
}
105+
106+
//+ ";CASE_INSENSITIVE_IDENTIFIERS=TRUE;";
91107
return DriverTypeEnum.H2_EMBEDDED.newConnectionProperties(url, "SA", "SA");
92108
}
93109
}

hapi-fhir-sql-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/JdbcUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static Set<String> getPrimaryKeyColumns(
9191
metadata.getPrimaryKeys(connection.getCatalog(), connection.getSchema(), theTableName)) {
9292
while (results.next()) {
9393
String columnName = results.getString("COLUMN_NAME");
94-
retVal.add(columnName);
94+
retVal.add(columnName.toUpperCase(Locale.US));
9595
}
9696
}
9797

0 commit comments

Comments
 (0)