From af5df1e535fb854b1e8070b9ffdd76ebee0986f8 Mon Sep 17 00:00:00 2001 From: vramik Date: Thu, 7 Nov 2019 11:16:10 +0100 Subject: [PATCH] KEYCLOAK-11808 Add support for MySQL8, update supported database versions --- .../updater/liquibase/MySQL8VarcharType.java | 51 +++++++++++++++++++ .../DefaultLiquibaseConnectionProvider.java | 5 ++ pom.xml | 6 +-- testsuite/integration-arquillian/pom.xml | 15 +++--- 4 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/MySQL8VarcharType.java diff --git a/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/MySQL8VarcharType.java b/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/MySQL8VarcharType.java new file mode 100644 index 000000000000..6eecd2619c9e --- /dev/null +++ b/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/MySQL8VarcharType.java @@ -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); + } +} diff --git a/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/conn/DefaultLiquibaseConnectionProvider.java b/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/conn/DefaultLiquibaseConnectionProvider.java index ea8373c04a5d..7f3e667ebdf2 100644 --- a/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/conn/DefaultLiquibaseConnectionProvider.java +++ b/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/conn/DefaultLiquibaseConnectionProvider.java @@ -23,6 +23,7 @@ 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.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 @@ protected void baseLiquibaseInitialization() { 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()); diff --git a/pom.xml b/pom.xml index 11ae9332493d..a2623044c7a6 100755 --- a/pom.xml +++ b/pom.xml @@ -117,12 +117,12 @@ ${jetty92.version} 3.5.5 - 5.1.29 + 8.0.18 4.2.0 7.1.0 - 9.3-1100-jdbc41 + 42.2.8 2.2.4 - 7.0.0.jre8 + 7.4.1.jre8 1.0.2.Final 1.0.0.Final 4.0.4 diff --git a/testsuite/integration-arquillian/pom.xml b/testsuite/integration-arquillian/pom.xml index 339fda231d30..34242c9519e9 100644 --- a/testsuite/integration-arquillian/pom.xml +++ b/testsuite/integration-arquillian/pom.xml @@ -412,15 +412,14 @@ keycloak keycloak keycloak - - jdbc:mysql://${auth.server.db.host}/${keycloak.connectionsJpa.database}?useSSL=false + jdbc:mysql://${auth.server.db.host}/${keycloak.connectionsJpa.database}?allowPublicKeyRetrieval=true mysql mysql-connector-java ${mysql.version} - mysql:5.7.25 + mysql:8.0.18 3306 false mysqld @@ -436,7 +435,7 @@ mysql mysql-connector-java ${mysql.version} - mysql57 + mysql80 false @@ -454,7 +453,7 @@ org.postgresql postgresql ${postgresql.version} - postgres:10.1 + postgres:11.5 5432 false postgres @@ -470,7 +469,7 @@ org.postgresql postgresql ${postgresql.version} - postgresql96 + postgresql115 false @@ -546,7 +545,7 @@ - db-allocator-db-mssql2016 + db-allocator-db-mssql2017 @@ -554,7 +553,7 @@ com.microsoft.sqlserver mssql-jdbc ${mssql.version} - mssql2016 + mssql2017 false