KEYCLOAK-11808 Add support for MySQL8, update supported database versions

This commit is contained in:
vramik 2019-11-07 11:16:10 +01:00 committed by Stian Thorgersen
parent 3a36569e20
commit af5df1e535
4 changed files with 66 additions and 11 deletions

View file

@ -0,0 +1,51 @@
/*
* Copyright 2019 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.connections.jpa.updater.liquibase;
import liquibase.database.Database;
import liquibase.database.core.MySQLDatabase;
import liquibase.datatype.DatabaseDataType;
import liquibase.datatype.core.VarcharType;
import liquibase.exception.DatabaseException;
/**
* Changes VARCHAR type with size greater than 255 to text type for MySQL 8 and newer.
*
* Resolves Limits on Table Column Count and Row Size for MySQL 8
*/
public class MySQL8VarcharType extends VarcharType {
@Override
public int getPriority() {
return super.getPriority() + 1; // Always take precedence over VarcharType
}
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof MySQLDatabase) {
try {
if (database.getDatabaseMajorVersion() >= 8 && getSize() > 255) {
return new DatabaseDataType(database.escapeDataTypeName("TEXT"), getSize());
}
} catch (DatabaseException e) {
throw new RuntimeException(e);
}
}
return super.toDatabaseDataType(database);
}
}

View file

@ -23,6 +23,7 @@ import liquibase.changelog.DatabaseChangeLog;
import liquibase.database.Database;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.datatype.DataTypeFactory;
import liquibase.exception.LiquibaseException;
import liquibase.logging.LogFactory;
import liquibase.logging.LogLevel;
@ -34,6 +35,7 @@ import org.jboss.logging.Logger;
import org.keycloak.Config;
import org.keycloak.connections.jpa.updater.liquibase.LiquibaseJpaUpdaterProvider;
import org.keycloak.connections.jpa.updater.liquibase.PostgresPlusDatabase;
import org.keycloak.connections.jpa.updater.liquibase.MySQL8VarcharType;
import org.keycloak.connections.jpa.updater.liquibase.UpdatedMariaDBDatabase;
import org.keycloak.connections.jpa.updater.liquibase.UpdatedMySqlDatabase;
import org.keycloak.connections.jpa.updater.liquibase.lock.CustomInsertLockRecordGenerator;
@ -99,6 +101,9 @@ public class DefaultLiquibaseConnectionProvider implements LiquibaseConnectionPr
DatabaseFactory.getInstance().register(new UpdatedMySqlDatabase());
DatabaseFactory.getInstance().register(new UpdatedMariaDBDatabase());
// Adding CustomVarcharType for MySQL 8 and newer
DataTypeFactory.getInstance().register(MySQL8VarcharType.class);
// Change command for creating lock and drop DELETE lock record from it
SqlGeneratorFactory.getInstance().register(new CustomInsertLockRecordGenerator());

View file

@ -117,12 +117,12 @@
<jetty9.version>${jetty92.version}</jetty9.version>
<liquibase.version>3.5.5</liquibase.version>
<mysql.version>5.1.29</mysql.version>
<mysql.version>8.0.18</mysql.version>
<osgi.version>4.2.0</osgi.version>
<pax.web.version>7.1.0</pax.web.version>
<postgresql.version>9.3-1100-jdbc41</postgresql.version>
<postgresql.version>42.2.8</postgresql.version>
<mariadb.version>2.2.4</mariadb.version>
<mssql.version>7.0.0.jre8</mssql.version>
<mssql.version>7.4.1.jre8</mssql.version>
<servlet.api.30.version>1.0.2.Final</servlet.api.30.version>
<servlet.api.40.version>1.0.0.Final</servlet.api.40.version>
<twitter4j.version>4.0.4</twitter4j.version>

View file

@ -412,15 +412,14 @@
<keycloak.connectionsJpa.database>keycloak</keycloak.connectionsJpa.database>
<keycloak.connectionsJpa.user>keycloak</keycloak.connectionsJpa.user>
<keycloak.connectionsJpa.password>keycloak</keycloak.connectionsJpa.password>
<!-- Disable SSL is needed when using newer JDBC drivers like mysql 8.0.12 to avoid warnings in the log -->
<keycloak.connectionsJpa.url>jdbc:mysql://${auth.server.db.host}/${keycloak.connectionsJpa.database}?useSSL=false</keycloak.connectionsJpa.url>
<keycloak.connectionsJpa.url>jdbc:mysql://${auth.server.db.host}/${keycloak.connectionsJpa.database}?allowPublicKeyRetrieval=true</keycloak.connectionsJpa.url>
<!-- JDBC properties point to "default" JDBC driver for the particular DB -->
<!-- For EAP testing, it is recommended to override those with system properties pointing to GAV of more appropriate JDBC driver -->
<!-- for the particular EAP version -->
<jdbc.mvn.groupId>mysql</jdbc.mvn.groupId>
<jdbc.mvn.artifactId>mysql-connector-java</jdbc.mvn.artifactId>
<jdbc.mvn.version>${mysql.version}</jdbc.mvn.version>
<docker.database.image>mysql:5.7.25</docker.database.image>
<docker.database.image>mysql:8.0.18</docker.database.image>
<docker.database.port>3306</docker.database.port>
<docker.database.skip>false</docker.database.skip>
<docker.database.cmd>mysqld</docker.database.cmd>
@ -436,7 +435,7 @@
<jdbc.mvn.groupId>mysql</jdbc.mvn.groupId>
<jdbc.mvn.artifactId>mysql-connector-java</jdbc.mvn.artifactId>
<jdbc.mvn.version>${mysql.version}</jdbc.mvn.version>
<dballocator.type>mysql57</dballocator.type>
<dballocator.type>mysql80</dballocator.type>
<dballocator.skip>false</dballocator.skip>
</properties>
</profile>
@ -454,7 +453,7 @@
<jdbc.mvn.groupId>org.postgresql</jdbc.mvn.groupId>
<jdbc.mvn.artifactId>postgresql</jdbc.mvn.artifactId>
<jdbc.mvn.version>${postgresql.version}</jdbc.mvn.version>
<docker.database.image>postgres:10.1</docker.database.image>
<docker.database.image>postgres:11.5</docker.database.image>
<docker.database.port>5432</docker.database.port>
<docker.database.skip>false</docker.database.skip>
<docker.database.cmd>postgres</docker.database.cmd>
@ -470,7 +469,7 @@
<jdbc.mvn.groupId>org.postgresql</jdbc.mvn.groupId>
<jdbc.mvn.artifactId>postgresql</jdbc.mvn.artifactId>
<jdbc.mvn.version>${postgresql.version}</jdbc.mvn.version>
<dballocator.type>postgresql96</dballocator.type>
<dballocator.type>postgresql115</dballocator.type>
<dballocator.skip>false</dballocator.skip>
</properties>
</profile>
@ -546,7 +545,7 @@
</properties>
</profile>
<profile>
<id>db-allocator-db-mssql2016</id>
<id>db-allocator-db-mssql2017</id>
<properties>
<!-- JDBC properties point to "default" JDBC driver for the particular DB -->
<!-- For EAP testing, it is recommended to override those with system properties pointing to GAV of more appropriate JDBC driver -->
@ -554,7 +553,7 @@
<jdbc.mvn.groupId>com.microsoft.sqlserver</jdbc.mvn.groupId>
<jdbc.mvn.artifactId>mssql-jdbc</jdbc.mvn.artifactId>
<jdbc.mvn.version>${mssql.version}</jdbc.mvn.version>
<dballocator.type>mssql2016</dballocator.type>
<dballocator.type>mssql2017</dballocator.type>
<dballocator.skip>false</dballocator.skip>
</properties>
</profile>