Adding TiDB dialect for Quarkus

Closes #41897

Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
Signed-off-by: Dennis Kniep <kniepdennis@gmail.com>
Co-authored-by: Dennis Kniep <kniepdennis@gmail.com>
This commit is contained in:
Alexander Schwartz
2025-08-26 22:44:45 +02:00
committed by GitHub
parent a01571c2cc
commit ca1e61047a
26 changed files with 92 additions and 51 deletions

View File

@@ -693,7 +693,7 @@ jobs:
timeout-minutes: 75
strategy:
matrix:
db: [postgres, mysql, oracle, mssql, mariadb]
db: [postgres, mysql, oracle, mssql, mariadb, tidb]
fail-fast: false
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

View File

@@ -140,6 +140,8 @@ public class Profile {
LOG_MDC("Mapped Diagnostic Context (MDC) information in logs", Type.PREVIEW),
DB_TIDB("TiDB database type", Type.EXPERIMENTAL),
/**
* @see <a href="https://github.com/keycloak/keycloak/issues/37967">Deprecate for removal the Instagram social broker</a>.
*/

View File

@@ -192,6 +192,18 @@ public final class Database {
getProperty(DatabaseOptions.DB_URL_PROPERTIES, namedProperty)),
List.of("org.keycloak.connections.jpa.updater.liquibase.UpdatedMySqlDatabase")
),
TIDB("tidb",
"com.mysql.cj.jdbc.MysqlXADataSource",
"com.mysql.cj.jdbc.Driver",
"org.hibernate.community.dialect.TiDBDialect",
// default URL looks like this: "jdbc:mysql://${kc.db-url-host:localhost}:${kc.db-url-port:3306}/${kc.db-url-database:keycloak}${kc.db-url-properties:}"
(namedProperty, alias) -> "jdbc:mysql://%s:%s/%s%s".formatted(
getProperty(DatabaseOptions.DB_URL_HOST, namedProperty, "localhost"),
getProperty(DatabaseOptions.DB_URL_PORT, namedProperty, "3306"),
getProperty(DatabaseOptions.DB_URL_DATABASE, namedProperty, "keycloak"),
getProperty(DatabaseOptions.DB_URL_PROPERTIES, namedProperty)),
List.of("org.keycloak.connections.jpa.updater.liquibase.UpdatedMySqlDatabase")
),
MARIADB("mariadb",
"org.mariadb.jdbc.MariaDbDataSource",
"org.mariadb.jdbc.Driver",

View File

@@ -90,6 +90,7 @@ import org.keycloak.config.MetricsOptions;
import org.keycloak.config.SecurityOptions;
import org.keycloak.config.TracingOptions;
import org.keycloak.config.TransactionOptions;
import org.keycloak.config.database.Database;
import org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory;
import org.keycloak.connections.jpa.JpaConnectionProvider;
import org.keycloak.connections.jpa.JpaConnectionSpi;
@@ -168,6 +169,7 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Handler;
import static org.keycloak.config.DatabaseOptions.DB;
import static org.keycloak.connections.jpa.util.JpaUtils.loadSpecificNamedQueries;
import static org.keycloak.quarkus.runtime.Environment.getCurrentOrCreateFeatureProfile;
import static org.keycloak.quarkus.runtime.Providers.getProviderManager;
@@ -381,6 +383,12 @@ class KeycloakProcessor {
@BuildStep
@Produce(ValidatePersistenceUnitsBuildItem.class)
void checkPersistenceUnits(List<PersistenceXmlDescriptorBuildItem> descriptors) {
if (Database.Vendor.TIDB.isOfKind(Configuration.getConfigValue(DB).getValue())) {
if (!Profile.isFeatureEnabled(Profile.Feature.DB_TIDB)){
throw new RuntimeException("The feature TiDB is not enabled");
}
}
List<String> notSetPersistenceUnitsDBKinds = descriptors.stream()
.map(PersistenceXmlDescriptorBuildItem::getDescriptor)
.filter(descriptor -> !descriptor.getName().equals(DEFAULT_PERSISTENCE_UNIT)) // not default persistence unit

View File

@@ -55,6 +55,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-community-dialects</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>

View File

@@ -133,7 +133,7 @@ public class IgnoredArtifacts {
final Set<String> jdbcArtifacts = vendorsOfAllDatasources.stream()
.map(vendor -> switch (vendor) {
case H2 -> JDBC_H2;
case MYSQL -> JDBC_MYSQL;
case MYSQL, TIDB -> JDBC_MYSQL;
case MARIADB -> JDBC_MARIADB;
case POSTGRES -> JDBC_POSTGRES;
case MSSQL -> JDBC_MSSQL;

View File

@@ -32,8 +32,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-debug-jpql <true|false>
Add JPQL information as comments to SQL statements to debug JPA SQL statement
generation. Default: false.
@@ -86,7 +86,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
--db-log-slow-queries-threshold-<datasource> <milliseconds>
Preview: Used for named <datasource>. Log SQL statements slower than the
configured threshold with logger org.hibernate.SQL_SLOW and log-level info.

View File

@@ -34,8 +34,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-debug-jpql <true|false>
Add JPQL information as comments to SQL statements to debug JPA SQL statement
generation. Default: false.
@@ -88,7 +88,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
--db-log-slow-queries-threshold-<datasource> <milliseconds>
Preview: Used for named <datasource>. Log SQL statements slower than the
configured threshold with logger org.hibernate.SQL_SLOW and log-level info.

View File

@@ -21,8 +21,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-driver <driver> The fully qualified class name of the JDBC driver. If not set, a default
driver is set accordingly to the chosen database.
@@ -36,7 +36,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
Transaction:

View File

@@ -27,8 +27,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-debug-jpql <true|false>
Add JPQL information as comments to SQL statements to debug JPA SQL statement
generation. Default: false.
@@ -81,7 +81,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
--db-log-slow-queries-threshold-<datasource> <milliseconds>
Preview: Used for named <datasource>. Log SQL statements slower than the
configured threshold with logger org.hibernate.SQL_SLOW and log-level info.

View File

@@ -27,8 +27,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-debug-jpql <true|false>
Add JPQL information as comments to SQL statements to debug JPA SQL statement
generation. Default: false.
@@ -81,7 +81,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
--db-log-slow-queries-threshold-<datasource> <milliseconds>
Preview: Used for named <datasource>. Log SQL statements slower than the
configured threshold with logger org.hibernate.SQL_SLOW and log-level info.

View File

@@ -27,8 +27,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-debug-jpql <true|false>
Add JPQL information as comments to SQL statements to debug JPA SQL statement
generation. Default: false.
@@ -81,7 +81,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
--db-log-slow-queries-threshold-<datasource> <milliseconds>
Preview: Used for named <datasource>. Log SQL statements slower than the
configured threshold with logger org.hibernate.SQL_SLOW and log-level info.

View File

@@ -27,8 +27,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-debug-jpql <true|false>
Add JPQL information as comments to SQL statements to debug JPA SQL statement
generation. Default: false.
@@ -81,7 +81,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
--db-log-slow-queries-threshold-<datasource> <milliseconds>
Preview: Used for named <datasource>. Log SQL statements slower than the
configured threshold with logger org.hibernate.SQL_SLOW and log-level info.

View File

@@ -75,8 +75,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-debug-jpql <true|false>
Add JPQL information as comments to SQL statements to debug JPA SQL statement
generation. Default: false.
@@ -129,7 +129,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
--db-log-slow-queries-threshold-<datasource> <milliseconds>
Preview: Used for named <datasource>. Log SQL statements slower than the
configured threshold with logger org.hibernate.SQL_SLOW and log-level info.

View File

@@ -142,8 +142,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-debug-jpql <true|false>
Add JPQL information as comments to SQL statements to debug JPA SQL statement
generation. Default: false.
@@ -196,7 +196,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
--db-log-slow-queries-threshold-<datasource> <milliseconds>
Preview: Used for named <datasource>. Log SQL statements slower than the
configured threshold with logger org.hibernate.SQL_SLOW and log-level info.

View File

@@ -123,8 +123,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-debug-jpql <true|false>
Add JPQL information as comments to SQL statements to debug JPA SQL statement
generation. Default: false.
@@ -177,7 +177,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
--db-log-slow-queries-threshold-<datasource> <milliseconds>
Preview: Used for named <datasource>. Log SQL statements slower than the
configured threshold with logger org.hibernate.SQL_SLOW and log-level info.

View File

@@ -143,8 +143,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-debug-jpql <true|false>
Add JPQL information as comments to SQL statements to debug JPA SQL statement
generation. Default: false.
@@ -197,7 +197,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
--db-log-slow-queries-threshold-<datasource> <milliseconds>
Preview: Used for named <datasource>. Log SQL statements slower than the
configured threshold with logger org.hibernate.SQL_SLOW and log-level info.

View File

@@ -122,8 +122,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-debug-jpql <true|false>
Add JPQL information as comments to SQL statements to debug JPA SQL statement
generation. Default: false.
@@ -176,7 +176,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
--db-log-slow-queries-threshold-<datasource> <milliseconds>
Preview: Used for named <datasource>. Log SQL statements slower than the
configured threshold with logger org.hibernate.SQL_SLOW and log-level info.

View File

@@ -142,8 +142,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-debug-jpql <true|false>
Add JPQL information as comments to SQL statements to debug JPA SQL statement
generation. Default: false.
@@ -196,7 +196,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
--db-log-slow-queries-threshold-<datasource> <milliseconds>
Preview: Used for named <datasource>. Log SQL statements slower than the
configured threshold with logger org.hibernate.SQL_SLOW and log-level info.

View File

@@ -120,8 +120,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-debug-jpql <true|false>
Add JPQL information as comments to SQL statements to debug JPA SQL statement
generation. Default: false.
@@ -174,7 +174,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
--db-log-slow-queries-threshold-<datasource> <milliseconds>
Preview: Used for named <datasource>. Log SQL statements slower than the
configured threshold with logger org.hibernate.SQL_SLOW and log-level info.

View File

@@ -140,8 +140,8 @@ Database:
--db <vendor> The database vendor. In production mode the default value of 'dev-file' is
deprecated, you should explicitly specify the db instead. Possible values
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres. Default:
dev-file.
are: dev-file, dev-mem, mariadb, mssql, mysql, oracle, postgres, tidb.
Default: dev-file.
--db-debug-jpql <true|false>
Add JPQL information as comments to SQL statements to debug JPA SQL statement
generation. Default: false.
@@ -194,7 +194,7 @@ Database - additional datasources (Preview):
Preview: Used for named <datasource>. The database vendor. In production mode
the default value of 'dev-file' is deprecated, you should explicitly specify
the db instead. Possible values are: dev-file, dev-mem, mariadb, mssql,
mysql, oracle, postgres.
mysql, oracle, postgres, tidb.
--db-log-slow-queries-threshold-<datasource> <milliseconds>
Preview: Used for named <datasource>. Log SQL statements slower than the
configured threshold with logger org.hibernate.SQL_SLOW and log-level info.

View File

@@ -1,5 +1,10 @@
package org.keycloak.testframework.database;
import org.keycloak.common.Profile;
import org.keycloak.testframework.annotations.InjectTestDatabase;
import org.keycloak.testframework.injection.InstanceContext;
import org.keycloak.testframework.server.KeycloakServerConfigBuilder;
public class TiDBDatabaseSupplier extends AbstractDatabaseSupplier {
@Override
@@ -7,6 +12,13 @@ public class TiDBDatabaseSupplier extends AbstractDatabaseSupplier {
return "tidb";
}
@Override
public KeycloakServerConfigBuilder intercept(KeycloakServerConfigBuilder serverConfig, InstanceContext<TestDatabase, InjectTestDatabase> instanceContext) {
KeycloakServerConfigBuilder builder = super.intercept(serverConfig, instanceContext);
builder.features(Profile.Feature.DB_TIDB);
return builder;
}
@Override
TestDatabase getTestDatabase() {
return new TiDBTestDatabase();

View File

@@ -43,7 +43,7 @@ class TiDBTestDatabase extends AbstractContainerTestDatabase {
@Override
public String getDatabaseVendor() {
return "mysql";
return "tidb";
}
@Override

View File

@@ -419,12 +419,13 @@
<profile>
<id>db-tidb</id>
<properties>
<keycloak.storage.connections.vendor>mysql</keycloak.storage.connections.vendor>
<keycloak.storage.connections.vendor>tidb</keycloak.storage.connections.vendor>
<keycloak.connectionsJpa.driver>com.mysql.jdbc.Driver</keycloak.connectionsJpa.driver>
<keycloak.connectionsJpa.database>test</keycloak.connectionsJpa.database>
<keycloak.connectionsJpa.user>root</keycloak.connectionsJpa.user>
<keycloak.connectionsJpa.password></keycloak.connectionsJpa.password>
<keycloak.connectionsJpa.url>jdbc:mysql://${auth.server.db.host}:${docker.database.port}/${keycloak.connectionsJpa.database}</keycloak.connectionsJpa.url>
<auth.server.feature>db-tidb</auth.server.feature>
<!-- 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 -->

View File

@@ -328,6 +328,8 @@
</property>
<property name="javaOpts">-Xms512m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=512m</property>
<property name="outputToConsole">true</property>
<property name="enabledFeatures">${auth.server.feature}</property>
<property name="disabledFeatures">${auth.server.feature.disable}</property>
</configuration>
</container>
<container qualifier="auth-server-quarkus-backend2" mode="manual" >
@@ -350,6 +352,8 @@
</property>
<property name="javaOpts">-Xms512m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=512m</property>
<property name="outputToConsole">true</property>
<property name="enabledFeatures">${auth.server.feature}</property>
<property name="disabledFeatures">${auth.server.feature.disable}</property>
</configuration>
</container>
</group>

View File

@@ -96,8 +96,6 @@
<auth.server.jgroups.mtls>false</auth.server.jgroups.mtls>
<auth.server.profile/>
<auth.server.feature/>
<auth.server.feature.disable/>
<auth.server.host2>${auth.server.host}</auth.server.host2> <!-- for broker and JS adapter tests; defaults to auth.server.host -->
<app.server.host>localhost</app.server.host>