Skip to content

Commit

Permalink
Merge pull request #159 from ebean-orm/fix/158
Browse files Browse the repository at this point in the history
#158 - fastMode fails with MySQL and Hikari and AutoCommit=true
  • Loading branch information
rbygrave authored Jul 2, 2024
2 parents 231c29c + 2ed655b commit 9173356
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
7 changes: 7 additions & 0 deletions ebean-migration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@

<!-- test dependencies -->

<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-slf4j-jpl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ List<MigrationMetaRow> fastReadMigrations(String sqlTable, Connection connection
}
}
} finally {
connection.rollback();
if (!connection.getAutoCommit()) {
connection.rollback();
}
}
return rows;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.ebean.migration;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import io.ebean.ddlrunner.DdlRunner;
import io.ebean.test.containers.*;
import org.junit.jupiter.api.Disabled;
Expand Down Expand Up @@ -210,13 +212,23 @@ public void mysql_migration() throws SQLException {

config.setMigrationPath("dbmig_basic");

MigrationRunner runner = new MigrationRunner(config);
runner.run();
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl(mysqlContainer.jdbcUrl());
hikariConfig.setUsername("mig_test");
hikariConfig.setPassword("test");

try (Connection connection = mysqlContainer.createConnection()) {
readQuery(connection, "select * from m1");
readQuery(connection, "select * from m2");
readQuery(connection, "select * from m3");
try (HikariDataSource ds = new HikariDataSource(hikariConfig)) {
MigrationRunner runner = new MigrationRunner(config);
try (Connection connection1 = ds.getConnection()) {
// connection1.setAutoCommit(false);
runner.run(connection1);
}

try (Connection connection = mysqlContainer.createConnection()) {
readQuery(connection, "select * from m1");
readQuery(connection, "select * from m2");
readQuery(connection, "select * from m3");
}
}

mysqlContainer.stopRemove();
Expand Down

0 comments on commit 9173356

Please sign in to comment.