diff --git a/ebean-migration/src/test/java/io/ebean/migration/MigrationRunnerTest.java b/ebean-migration/src/test/java/io/ebean/migration/MigrationRunnerTest.java index 24bc6bf..eb1df6f 100644 --- a/ebean-migration/src/test/java/io/ebean/migration/MigrationRunnerTest.java +++ b/ebean-migration/src/test/java/io/ebean/migration/MigrationRunnerTest.java @@ -56,6 +56,37 @@ public void run_when_fileSystemResources() { runner.run(); } + @Test + public void run_when_error() throws SQLException { + + DataSourceConfig dataSourceConfig = new DataSourceConfig(); + dataSourceConfig.setDriver("org.h2.Driver"); + dataSourceConfig.setUrl("jdbc:h2:mem:err.db"); + dataSourceConfig.setUsername("sa"); + dataSourceConfig.setPassword(""); + + DataSourcePool dataSource = DataSourceFactory.create("test", dataSourceConfig); + + MigrationConfig config = createMigrationConfig(); + config.setMigrationPath("dbmig_error"); + MigrationRunner runner = new MigrationRunner(config); + try { + runner.run(dataSource); + } catch (Exception expected) { + try (Connection connection = dataSource.getConnection()) { + try (var pstmt = connection.prepareStatement("select count(*) from m1")) { + try (var resultSet = pstmt.executeQuery()) { + assertThat(resultSet.next()).isTrue(); + int val = resultSet.getInt(1); + assertThat(val).isEqualTo(0); + } + } catch (SQLException ex) { + fail(ex); + } + } + } + } + @Test public void run_when_suppliedConnection() { diff --git a/ebean-migration/src/test/resources/dbmig_error/1.1__initial.sql b/ebean-migration/src/test/resources/dbmig_error/1.1__initial.sql new file mode 100644 index 0000000..7d68a2e --- /dev/null +++ b/ebean-migration/src/test/resources/dbmig_error/1.1__initial.sql @@ -0,0 +1 @@ +create table m1 (id integer, acol varchar(20)); diff --git a/ebean-migration/src/test/resources/dbmig_error/1.2__insert.sql b/ebean-migration/src/test/resources/dbmig_error/1.2__insert.sql new file mode 100644 index 0000000..3bedec8 --- /dev/null +++ b/ebean-migration/src/test/resources/dbmig_error/1.2__insert.sql @@ -0,0 +1 @@ +insert into m1 (id, acol) values (1,'hi'); diff --git a/ebean-migration/src/test/resources/dbmig_error/1.3__error.sql b/ebean-migration/src/test/resources/dbmig_error/1.3__error.sql new file mode 100644 index 0000000..8679eef --- /dev/null +++ b/ebean-migration/src/test/resources/dbmig_error/1.3__error.sql @@ -0,0 +1 @@ +not valid sql