-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use automatic detection of earlyChecksumMode rather than IllegalState…
…Exception
- Loading branch information
1 parent
afaa4a6
commit 3ef3c77
Showing
10 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
ebean-migration/src/test/java/io/ebean/migration/runner/MigrationEarlyModeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package io.ebean.migration.runner; | ||
|
||
import io.avaje.applog.AppLog; | ||
import io.ebean.datasource.DataSourceConfig; | ||
import io.ebean.datasource.DataSourceFactory; | ||
import io.ebean.datasource.DataSourcePool; | ||
import io.ebean.migration.MigrationConfig; | ||
import io.ebean.migration.MigrationRunner; | ||
import io.ebean.test.containers.PostgresContainer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
import java.util.Map; | ||
|
||
import static java.lang.System.Logger.Level.INFO; | ||
import static org.assertj.core.api.Assertions.fail; | ||
|
||
class MigrationEarlyModeTest { | ||
|
||
private static final System.Logger log = AppLog.getLogger(MigrationEarlyModeTest.class); | ||
|
||
String un = "mig_early"; | ||
String pw = "test"; | ||
|
||
private static PostgresContainer createPostgres() { | ||
return PostgresContainer.builder("15") | ||
.port(9823) | ||
.containerName("pg15") | ||
.user("mig_early") | ||
.dbName("mig_early") | ||
.build(); | ||
} | ||
|
||
// @Disabled | ||
@Test | ||
void testEarlyMode() { | ||
createPostgres().startWithDropCreate(); | ||
|
||
String url = createPostgres().jdbcUrl(); | ||
DataSourcePool dataSource = dataSource(url); | ||
|
||
MigrationConfig config = new MigrationConfig(); | ||
config.setDbUrl(url); | ||
config.setDbUsername(un); | ||
config.setDbPassword(pw); | ||
config.setMigrationPath("dbmig_postgres_early"); | ||
config.setRunPlaceholderMap(Map.of("my_table_name", "my_table")); | ||
|
||
// legacy mode | ||
new MigrationRunner(config).run(dataSource); | ||
|
||
// early mode | ||
log.log(INFO, "-- EARLY MODE -- "); | ||
config.setEarlyChecksumMode(true); | ||
new MigrationRunner(config).run(dataSource); | ||
|
||
log.log(INFO, "-- RE-RUN EARLY MODE -- "); | ||
new MigrationRunner(config).run(dataSource); | ||
|
||
log.log(INFO, "-- EARLY MODE AGAIN -- "); | ||
config.setEarlyChecksumMode(false); | ||
new MigrationRunner(config).run(dataSource); | ||
|
||
config.setRunPlaceholderMap(Map.of("my_table_name", "my_table", "other_table_name", "other")); | ||
config.setMigrationPath("dbmig_postgres_early1"); | ||
|
||
new MigrationRunner(config).run(dataSource); | ||
|
||
config.setEarlyChecksumMode(true); | ||
new MigrationRunner(config).run(dataSource); | ||
|
||
} | ||
|
||
private DataSourcePool dataSource(String url) { | ||
DataSourceConfig dataSourceConfig = new DataSourceConfig() | ||
.setUrl(url) | ||
.setUsername(un) | ||
.setPassword(pw); | ||
return DataSourceFactory.create("mig_early", dataSourceConfig); | ||
} | ||
|
||
// private static void dropTable(Connection conn) throws SQLException { | ||
// try (PreparedStatement stmt = conn.prepareStatement("drop table if exists db_migration")) { | ||
// stmt.executeUpdate(); | ||
// } | ||
// } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
ebean-migration/src/test/resources/dbmig_postgres_early/1.0__m0.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
create table ${my_table_name} (id integer, acol varchar(20), bcol timestamp); |
1 change: 1 addition & 0 deletions
1
ebean-migration/src/test/resources/dbmig_postgres_early/1.1__m1.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
create table m1 (id integer, acol varchar(20)); |
3 changes: 3 additions & 0 deletions
3
ebean-migration/src/test/resources/dbmig_postgres_early1/1.0__m0.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
create table ${my_table_name} (id integer, acol varchar(20), bcol timestamp); |
1 change: 1 addition & 0 deletions
1
ebean-migration/src/test/resources/dbmig_postgres_early1/1.1__m1.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
create table m1 (id integer, acol varchar(20)); |
3 changes: 3 additions & 0 deletions
3
ebean-migration/src/test/resources/dbmig_postgres_early1/2.0__m2.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
create table ${other_table_name} (acol varchar(20)); |
3 changes: 3 additions & 0 deletions
3
ebean-migration/src/test/resources/dbmig_postgres_early1/2.1__m3.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
create table m4 (acol varchar(20)); |