Skip to content

Commit

Permalink
Merge pull request #147 from ebean-orm/feature/add-fastmode
Browse files Browse the repository at this point in the history
Add support for "*" for PatchResetChecksumOn to mean patch all mismatched checksums
  • Loading branch information
rbygrave authored Nov 2, 2023
2 parents de2fdfd + 42872b1 commit 455e2ef
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,13 @@ boolean skipMigration(int checksum, int checksum2, LocalMigrationResource local,

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

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

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

private boolean isResetOnVersion(String version) {
return patchResetChecksumVersions != null && patchResetChecksumVersions.contains(version);
return patchResetChecksumVersions != null && (patchResetChecksumVersions.contains(version) || patchResetChecksumVersions.contains("*"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.ebean.migration;

import io.ebean.datasource.DataSourceConfig;
import io.ebean.datasource.DataSourceFactory;
import io.ebean.datasource.DataSourcePool;
import org.junit.jupiter.api.Test;

class MigrationRunner_PatchResetTest {

@Test
void patchReset() {

String url = "jdbc:h2:mem:patchReset";
DataSourceConfig dataSourceConfig = new DataSourceConfig()
.setUrl(url)
.setUsername("sa")
.setPassword("");

DataSourcePool dataSource = DataSourceFactory.create("test", dataSourceConfig);

MigrationConfig config = new MigrationConfig();
config.setPlatform("h2");

config.setMigrationPath("indexPatchReset_0");
MigrationRunner runner = new MigrationRunner(config);
runner.run(dataSource);

// add an index file now, expect automatically go to early mode + patch checksums
config.setMigrationPath("indexPatchReset_1");
config.setPatchResetChecksumOn("*");
new MigrationRunner(config).run(dataSource);

dataSource.shutdown();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- apply changes
create table m1 (
id integer generated by default as identity not null,
name varchar(255),
constraint pk_m1 primary key (id)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
insert into m1 (name) values ('hi');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create table m2 (acol varchar(10));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1, 1.0__initial.sql
2, 1.1.sql
3, 1.2.sql

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- apply changes
create table m1 (
id integer generated by default as identity not null,
name varchar(255),
constraint pk_m1 primary key (id)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
insert into m1 (name) values ('hi');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create table m2 (acol varchar(10));

0 comments on commit 455e2ef

Please sign in to comment.