Skip to content

Commit 8518b23

Browse files
committed
BugFix: Do not run non-transactional migrations when checkStateOnly
Also refactor rename checkState -> checkStateOnly
1 parent e4b01e3 commit 8518b23

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

ebean-migration/src/main/java/io/ebean/migration/MigrationRunner.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private Connection getConnection(DataSource dataSource) {
8585
/**
8686
* Run the migrations if there are any that need running.
8787
*/
88-
protected void run(Connection connection, boolean checkStateMode) {
88+
protected void run(Connection connection, boolean checkStateOnly) {
8989
try {
9090
LocalMigrationResources resources = new LocalMigrationResources(migrationConfig);
9191
if (!resources.readResources() && !resources.readInitResources()) {
@@ -98,17 +98,17 @@ protected void run(Connection connection, boolean checkStateMode) {
9898
MigrationPlatform platform = derivePlatformName(migrationConfig, connection);
9999
new MigrationSchema(migrationConfig, connection).createAndSetIfNeeded();
100100

101-
MigrationTable table = new MigrationTable(migrationConfig, connection, checkStateMode, platform);
101+
MigrationTable table = new MigrationTable(migrationConfig, connection, checkStateOnly, platform);
102102
table.createIfNeededAndLock();
103103
try {
104104
List<LocalMigrationResource> migrations = resources.getVersions();
105-
runMigrations(migrations, table, checkStateMode);
105+
runMigrations(migrations, table, checkStateOnly);
106106
connection.commit();
107-
if (!checkStateMode) {
107+
if (!checkStateOnly) {
108108
long exeMillis = System.currentTimeMillis() - start;
109109
log.log(INFO, "DB migrations completed in {0}ms - executed:{1} size:{2}", exeMillis, table.count(), migrations.size());
110+
table.runNonTransactional();
110111
}
111-
table.runNonTransactional();
112112
} finally {
113113
table.unlockMigrationTable();
114114
}

ebean-migration/src/main/java/io/ebean/migration/runner/MigrationTable.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public final class MigrationTable {
2626
private static final String INIT_VER_0 = "0";
2727

2828
private final Connection connection;
29-
private final boolean checkState;
29+
private final boolean checkStateOnly;
3030
private final MigrationPlatform platform;
3131
private final MigrationScriptRunner scriptRunner;
3232
private final String catalog;
@@ -72,11 +72,11 @@ public final class MigrationTable {
7272
/**
7373
* Construct with server, configuration and jdbc connection (DB admin user).
7474
*/
75-
public MigrationTable(MigrationConfig config, Connection connection, boolean checkState, MigrationPlatform platform) {
75+
public MigrationTable(MigrationConfig config, Connection connection, boolean checkStateOnly, MigrationPlatform platform) {
7676
this.platform = platform;
7777
this.connection = connection;
7878
this.scriptRunner = new MigrationScriptRunner(connection, platform);
79-
this.checkState = checkState;
79+
this.checkStateOnly = checkStateOnly;
8080
this.migrations = new LinkedHashMap<>();
8181
this.catalog = null;
8282
this.allowErrorInRepeatable = config.isAllowErrorInRepeatable();
@@ -322,7 +322,7 @@ private boolean runMigration(LocalMigrationResource local, MigrationMetaRow exis
322322
private boolean patchInsertMigration(LocalMigrationResource local, int checksum) throws SQLException {
323323
if (patchInsertVersions != null && patchInsertVersions.contains(local.key())) {
324324
log.log(INFO, "Patch migration, insert into history {0}", local.getLocation());
325-
if (!checkState) {
325+
if (!checkStateOnly) {
326326
insertIntoHistory(local, checksum, 0);
327327
}
328328
return true;
@@ -356,7 +356,7 @@ boolean skipMigration(int checksum, LocalMigrationResource local, MigrationMetaR
356356
*/
357357
private boolean patchResetChecksum(MigrationMetaRow existing, int newChecksum) throws SQLException {
358358
if (isResetOnVersion(existing.getVersion())) {
359-
if (!checkState) {
359+
if (!checkStateOnly) {
360360
existing.resetChecksum(newChecksum, connection, updateChecksumSql);
361361
}
362362
return true;
@@ -373,7 +373,7 @@ private boolean isResetOnVersion(String version) {
373373
* Run a migration script as new migration or update on existing repeatable migration.
374374
*/
375375
private void executeMigration(LocalMigrationResource local, String script, int checksum, MigrationMetaRow existing) throws SQLException {
376-
if (checkState) {
376+
if (checkStateOnly) {
377377
checkMigrations.add(local);
378378
// simulate the migration being run such that following migrations also match
379379
addMigration(local.key(), createMetaRow(local, checksum, 1));

0 commit comments

Comments
 (0)