Skip to content

Commit 5834216

Browse files
committed
Use the lower_case_table_names flag on mariadb
1 parent 21a50cc commit 5834216

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

server/src/main/java/org/cloudfoundry/identity/uaa/db/DatabaseInformation1_5_3.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* *****************************************************************************
3-
* Cloud Foundry
3+
* Cloud Foundry
44
* Copyright (c) [2009-2016] Pivotal Software, Inc. All Rights Reserved.
55
*
66
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
@@ -13,20 +13,18 @@
1313
*******************************************************************************/
1414
package org.cloudfoundry.identity.uaa.db;
1515

16+
import org.springframework.jdbc.core.RowMapper;
17+
1618
import java.sql.ResultSet;
1719
import java.sql.SQLException;
18-
import java.util.Arrays;
19-
import java.util.Collections;
2020
import java.util.List;
2121

22-
import org.springframework.jdbc.core.RowMapper;
23-
2422
/**
2523
* Created by fhanik on 3/5/14.
2624
*/
2725
public class DatabaseInformation1_5_3 {
2826

29-
public static List<String> tableNames = Collections.unmodifiableList(Arrays.asList(
27+
public static final List<String> tableNames = List.of(
3028
"users",
3129
"sec_audit",
3230
"oauth_client_details",
@@ -35,8 +33,7 @@ public class DatabaseInformation1_5_3 {
3533
"oauth_code",
3634
"authz_approvals",
3735
"external_group_mapping"
38-
39-
));
36+
);
4037

4138
public static boolean processColumn(ColumnInfo column) {
4239
return (!column.columnName.equals(column.columnName.toLowerCase())) &&

server/src/main/java/org/cloudfoundry/identity/uaa/db/beans/DatabaseConfiguration.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,28 @@ JdbcUrlCustomizer jdbcUrlAddTimeoutCustomizer(DatabaseProperties databasePropert
9999
}
100100

101101
/**
102-
* Allow mariadb driver to connect to mysql scheme urls
102+
* Use lower case table names with the mariadb driver
103+
* and allow connection to mysql scheme urls
103104
*/
104105
@Bean
105106
@Profile("mysql")
106-
JdbcUrlCustomizer jdbcUrlAddPermitMysqlSchemeCustomizer(DatabaseProperties databaseProperties) {
107+
JdbcUrlCustomizer jdbcUrlMariaDbSchemeCustomizer(DatabaseProperties databaseProperties) {
107108
return url -> {
108-
if (databaseProperties.getDriverClassName().contains("mariadb") && url.startsWith("jdbc:mysql") && !url.contains("permitMysqlScheme=")) {
109+
if (!url.startsWith("jdbc:mysql")) {
110+
return url;
111+
}
112+
if (!databaseProperties.getDriverClassName().contains("mariadb")) {
113+
return url;
114+
}
115+
116+
// this is a mysql scheme url with the mariadb driver
117+
if (!url.contains("permitMysqlScheme=")) {
118+
String connectorCharacter = url.contains("?") ? "&" : "?";
119+
url += connectorCharacter + "permitMysqlScheme=true";
120+
}
121+
if (!url.contains("lower_case_table_names")) {
109122
String connectorCharacter = url.contains("?") ? "&" : "?";
110-
return url + connectorCharacter + "permitMysqlScheme=true";
123+
url += connectorCharacter + "lower_case_table_names=1";
111124
}
112125
return url;
113126
};

server/src/test/java/org/cloudfoundry/identity/uaa/db/beans/DatabasePropertiesTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ void dataSourceUrlConfiguration() {
7373
assertThat(dataSource.getUrl())
7474
.containsPattern("jdbc:postgresql:uaa(_\\d+)?")
7575
.containsPattern("\\?connectTimeout=10\\b")
76-
.doesNotContain("permitMysqlScheme");
76+
.doesNotContain("permitMysqlScheme")
77+
.doesNotContain("lower_case_table_names");
7778
}
7879
}
7980

@@ -112,7 +113,8 @@ void dataSourceUrlConfiguration() {
112113
.containsPattern("\\?useSSL=true")
113114
.containsPattern("&trustServerCertificate=true")
114115
.containsPattern("&connectTimeout=10000")
115-
.containsPattern("&permitMysqlScheme=true");
116+
.containsPattern("&permitMysqlScheme=true")
117+
.containsPattern("&lower_case_table_names=1");
116118
}
117119
}
118120
}

0 commit comments

Comments
 (0)