Skip to content

Commit

Permalink
H2Util: Exclude PostgreSQL schema PG_CATALOG from being reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Undover authored and rpost committed Apr 6, 2024
1 parent 38cde2b commit 1687094
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.cronn.testutils.h2;

import org.springframework.test.context.TestPropertySource;

@TestPropertySource(properties = {
"spring.datasource.url=jdbc:h2:mem:testdb;INIT=CREATE SCHEMA IF NOT EXISTS SECOND_SCHEMA;MODE=PostgreSQL",
})
public abstract class H2PostgresModeUtilTest extends H2UtilTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int countRows(String table) {
}

int countTables() {
return jdbcTemplate.queryForObject("select count(*) from information_schema.tables where table_type in ('TABLE', 'BASE TABLE') and table_schema <> 'INFORMATION_SCHEMA'", Integer.class);
return jdbcTemplate.queryForObject("select count(*) from information_schema.tables where table_type in ('TABLE', 'BASE TABLE') and table_schema not in ('INFORMATION_SCHEMA', 'PG_CATALOG')", Integer.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package de.cronn.testutils.h2.v1_4;

public class H2PostgresModeUtilTest extends de.cronn.testutils.h2.H2PostgresModeUtilTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package de.cronn.testutils.h2.v2_0;

public class H2PostgresModeUtilTest extends de.cronn.testutils.h2.H2PostgresModeUtilTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package de.cronn.testutils.h2.v2_1;

public class H2PostgresModeUtilTest extends de.cronn.testutils.h2.H2PostgresModeUtilTest {
}
2 changes: 1 addition & 1 deletion src/main/java/de/cronn/testutils/h2/H2Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public static Set<Table> getTableNames(Connection con) throws SQLException {
Set<Table> tableNames = new LinkedHashSet<>();
String selectAllTables = "SELECT * FROM INFORMATION_SCHEMA.TABLES " +
"WHERE TABLE_TYPE IN ('TABLE' /* h2 v1.4 */, 'BASE TABLE' /* h2 v2.x */) " +
"AND TABLE_SCHEMA <> 'INFORMATION_SCHEMA'";
"AND TABLE_SCHEMA NOT IN ('INFORMATION_SCHEMA', 'PG_CATALOG')";
try (PreparedStatement stmt = con.prepareStatement(selectAllTables); ResultSet tables = stmt.executeQuery()) {
while (tables.next()) {
String schema = tables.getString("TABLE_SCHEMA");
Expand Down

0 comments on commit 1687094

Please # to comment.