Skip to content

Commit 82d913d

Browse files
alastorimbellade
authored andcommitted
HHH-19997 Fix TiDB support in docker_db.sh and local.databases.gradle
1 parent 4d780fb commit 82d913d

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

docker_db.sh

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,68 @@ EOF
12821282
}
12831283

12841284
tidb() {
1285-
tidb_5_4
1285+
tidb_8_5
1286+
}
1287+
1288+
tidb_8_5() {
1289+
$CONTAINER_CLI rm -f tidb || true
1290+
$CONTAINER_CLI run --name tidb -p4000:4000 -d ${DB_IMAGE_TIDB_8_5:-docker.io/pingcap/tidb:v8.5.4}
1291+
1292+
# Wait for TiDB to start
1293+
OUTPUT=
1294+
n=0
1295+
until [ "$n" -gt 15 ]; do
1296+
OUTPUT=$($CONTAINER_CLI logs tidb 2>&1)
1297+
if [[ $OUTPUT == *"server is running"* ]]; then
1298+
break;
1299+
fi
1300+
n=$((n+1))
1301+
echo "Waiting for TiDB to start..."
1302+
sleep 5
1303+
done
1304+
1305+
if [ "$n" -gt 15 ]; then
1306+
echo "TiDB failed to start after 75 seconds"
1307+
exit 1
1308+
else
1309+
echo "TiDB successfully started"
1310+
fi
1311+
1312+
# Wait for TiDB to accept connections
1313+
n=0
1314+
until [ "$n" -gt 10 ]; do
1315+
if $CONTAINER_CLI run --rm --network container:tidb docker.io/mysql:8.0 \
1316+
mysqladmin -h 127.0.0.1 -P 4000 -uroot ping >/dev/null 2>&1; then
1317+
break;
1318+
fi
1319+
n=$((n+1))
1320+
echo "Waiting for TiDB to be ready..."
1321+
sleep 3
1322+
done
1323+
1324+
if [ "$n" -gt 10 ]; then
1325+
echo "TiDB failed to become ready after 30 seconds"
1326+
exit 1
1327+
else
1328+
echo "TiDB is ready"
1329+
fi
1330+
1331+
# Create databases
1332+
databases=()
1333+
for n in $(seq 1 $DB_COUNT)
1334+
do
1335+
databases+=("hibernate_orm_test_${n}")
1336+
done
1337+
create_cmd=
1338+
create_cmd+="CREATE DATABASE IF NOT EXISTS hibernate_orm_test;"
1339+
create_cmd+="CREATE USER IF NOT EXISTS 'hibernate_orm_test'@'%' IDENTIFIED BY 'hibernate_orm_test';"
1340+
create_cmd+="GRANT ALL ON hibernate_orm_test.* TO 'hibernate_orm_test'@'%';"
1341+
for i in "${!databases[@]}";do
1342+
create_cmd+="CREATE DATABASE IF NOT EXISTS ${databases[i]}; GRANT ALL ON ${databases[i]}.* TO 'hibernate_orm_test'@'%';"
1343+
done
1344+
$CONTAINER_CLI run --rm --network container:tidb docker.io/mysql:8.0 \
1345+
mysql -h 127.0.0.1 -P 4000 -uroot -e "${create_cmd}" 2>/dev/null
1346+
echo "TiDB databases were successfully setup"
12861347
}
12871348

12881349
tidb_5_4() {
@@ -1445,6 +1506,7 @@ if [ -z ${1} ]; then
14451506
echo -e "\tpostgresql_13"
14461507
echo -e "\tsybase"
14471508
echo -e "\ttidb"
1509+
echo -e "\ttidb_8_5"
14481510
echo -e "\ttidb_5_4"
14491511
echo -e "\informix"
14501512
echo -e "\informix_14_10"

local-build-plugins/src/main/groovy/local.databases.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ ext {
171171
'connection.init_sql' : ''
172172
],
173173
tidb : [
174-
'db.dialect' : 'org.hibernate.dialect.TiDBDialect',
175-
'jdbc.driver': 'com.mysql.jdbc.Driver',
174+
'db.dialect' : 'org.hibernate.community.dialect.TiDBDialect',
175+
'jdbc.driver': 'com.mysql.cj.jdbc.Driver',
176176
'jdbc.user' : 'hibernate_orm_test',
177177
'jdbc.pass' : 'hibernate_orm_test',
178178
'jdbc.url' : 'jdbc:mysql://' + dbHost + ':4000/hibernate_orm_test',
179-
'jdbc.datasource' : 'com.mysql.jdbc.Driver',
179+
'jdbc.datasource' : 'com.mysql.cj.jdbc.Driver',
180180
// 'jdbc.datasource' : 'com.mysql.cj.jdbc.MysqlDataSource',
181181
'connection.init_sql' : ''
182182
],

0 commit comments

Comments
 (0)