Skip to content

Commit 42872b1

Browse files
committed
Add support for "*" for PatchResetChecksumOn to mean patch all mismatched checksums
Use via: migrationConfig.setPatchResetChecksumOn("*"); All checksums that are mismatched will be patched to the new checksum value.
1 parent 38aeac2 commit 42872b1

File tree

9 files changed

+59
-3
lines changed

9 files changed

+59
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,13 @@ boolean skipMigration(int checksum, int checksum2, LocalMigrationResource local,
366366

367367
} else if (patchLegacyChecksums && (existing.checksum() == checksum2 || checksum2 == AUTO_PATCH_CHECKSUM)) {
368368
if (!checkStateOnly) {
369-
log.log(INFO, "Patch migration, set early mode checksum on {0}", local.location());
369+
log.log(INFO, "Auto patch migration, set early mode checksum on {0} to {1,number} from {2,number}", local.location(), checksum, existing.checksum());
370370
existing.resetChecksum(checksum, connection, updateChecksumSql);
371371
}
372372
return true;
373373

374374
} else if (patchResetChecksum(existing, checksum)) {
375-
log.log(INFO, "Patch migration, reset checksum on {0}", local.location());
375+
log.log(INFO, "Patch migration, reset checksum on {0} to {1,number} from {2,number}", local.location(), checksum, existing.checksum());
376376
return true;
377377

378378
} else if (local.isRepeatable() || skipChecksum) {
@@ -398,7 +398,7 @@ private boolean patchResetChecksum(MigrationMetaRow existing, int newChecksum) t
398398
}
399399

400400
private boolean isResetOnVersion(String version) {
401-
return patchResetChecksumVersions != null && patchResetChecksumVersions.contains(version);
401+
return patchResetChecksumVersions != null && (patchResetChecksumVersions.contains(version) || patchResetChecksumVersions.contains("*"));
402402
}
403403

404404
/**
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.ebean.migration;
2+
3+
import io.ebean.datasource.DataSourceConfig;
4+
import io.ebean.datasource.DataSourceFactory;
5+
import io.ebean.datasource.DataSourcePool;
6+
import org.junit.jupiter.api.Test;
7+
8+
class MigrationRunner_PatchResetTest {
9+
10+
@Test
11+
void patchReset() {
12+
13+
String url = "jdbc:h2:mem:patchReset";
14+
DataSourceConfig dataSourceConfig = new DataSourceConfig()
15+
.setUrl(url)
16+
.setUsername("sa")
17+
.setPassword("");
18+
19+
DataSourcePool dataSource = DataSourceFactory.create("test", dataSourceConfig);
20+
21+
MigrationConfig config = new MigrationConfig();
22+
config.setPlatform("h2");
23+
24+
config.setMigrationPath("indexPatchReset_0");
25+
MigrationRunner runner = new MigrationRunner(config);
26+
runner.run(dataSource);
27+
28+
// add an index file now, expect automatically go to early mode + patch checksums
29+
config.setMigrationPath("indexPatchReset_1");
30+
config.setPatchResetChecksumOn("*");
31+
new MigrationRunner(config).run(dataSource);
32+
33+
dataSource.shutdown();
34+
}
35+
36+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- apply changes
2+
create table m1 (
3+
id integer generated by default as identity not null,
4+
name varchar(255),
5+
constraint pk_m1 primary key (id)
6+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
insert into m1 (name) values ('hi');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
create table m2 (acol varchar(10));
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1, 1.0__initial.sql
2+
2, 1.1.sql
3+
3, 1.2.sql
4+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- apply changes
2+
create table m1 (
3+
id integer generated by default as identity not null,
4+
name varchar(255),
5+
constraint pk_m1 primary key (id)
6+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
insert into m1 (name) values ('hi');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
create table m2 (acol varchar(10));

0 commit comments

Comments
 (0)