Skip to content

Commit 2a88328

Browse files
authored
Update pg index health (#176)
* New version * Refactor tests * Refactor tests #2
1 parent 7d3d460 commit 2a88328

File tree

7 files changed

+38
-49
lines changed

7 files changed

+38
-49
lines changed

common-internal-bom/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies {
1212
api(platform("org.assertj:assertj-bom:3.26.3"))
1313
api(platform("org.testcontainers:testcontainers-bom:1.20.3"))
1414
api(platform("org.junit:junit-bom:5.11.3"))
15-
api(platform("io.github.mfvanek:pg-index-health-bom:0.13.1"))
15+
api(platform("io.github.mfvanek:pg-index-health-bom:0.13.2"))
1616

1717
constraints {
1818
api("org.liquibase:liquibase-core:4.29.2")

docker/docker-compose-base.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ services:
8686

8787
postgres:
8888
container_name: postgres
89-
image: postgres:16.4
89+
image: postgres:17.0
9090
shm_size: "2gb"
9191
environment:
9292
POSTGRES_DB: "otel_demo_db"

spring-boot-2-demo-app/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ dependencies {
2121

2222
implementation("org.springframework.kafka:spring-kafka")
2323
implementation("io.opentelemetry:opentelemetry-exporter-otlp")
24-
implementation("org.springframework.cloud:spring-cloud-starter-sleuth") {
24+
implementation("org.springframework.cloud:spring-cloud-starter-sleuth:3.1.11") {
25+
because("The version is higher than in BOM")
2526
exclude(group = "org.springframework.cloud", module = "spring-cloud-sleuth-brave")
2627
}
2728
implementation("org.springframework.cloud:spring-cloud-sleuth-otel-autoconfigure")

spring-boot-2-demo-app/src/test/java/io/github/mfvanek/spring/boot2/test/IndexesMaintenanceTest.java

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnHost;
44
import io.github.mfvanek.pg.common.maintenance.Diagnostic;
55
import io.github.mfvanek.pg.model.DbObject;
6-
import io.github.mfvanek.pg.model.column.Column;
7-
import io.github.mfvanek.pg.model.table.Table;
6+
import io.github.mfvanek.pg.model.PgContext;
7+
import io.github.mfvanek.pg.model.table.TableNameAware;
88
import io.github.mfvanek.spring.boot2.test.support.TestBase;
99
import org.junit.jupiter.api.DisplayName;
1010
import org.junit.jupiter.api.Test;
1111
import org.springframework.beans.factory.annotation.Autowired;
1212

1313
import java.util.List;
14+
import java.util.function.Predicate;
1415

1516
import static org.assertj.core.api.Assertions.assertThat;
16-
import static org.assertj.core.api.InstanceOfAssertFactories.list;
1717

1818
class IndexesMaintenanceTest extends TestBase {
1919

@@ -25,33 +25,27 @@ class IndexesMaintenanceTest extends TestBase {
2525
void checkPostgresVersion() {
2626
final String pgVersion = jdbcTemplate.queryForObject("select version();", String.class);
2727
assertThat(pgVersion)
28-
.startsWith("PostgreSQL 16.4");
28+
.startsWith("PostgreSQL 17.0");
2929
}
3030

3131
@Test
3232
void databaseStructureCheckForPublicSchema() {
3333
assertThat(checks)
3434
.hasSameSizeAs(Diagnostic.values());
3535

36-
checks.forEach(check -> {
37-
switch (check.getDiagnostic()) {
38-
case TABLES_WITHOUT_PRIMARY_KEY, TABLES_WITHOUT_DESCRIPTION -> assertThat(check.check())
39-
.asInstanceOf(list(Table.class))
40-
.hasSize(1)
41-
.containsExactly(Table.of("databasechangelog", 0L));
42-
43-
case COLUMNS_WITHOUT_DESCRIPTION -> assertThat(check.check())
44-
.asInstanceOf(list(Column.class))
45-
.hasSize(14)
46-
.allSatisfy(column -> assertThat(column.getTableName()).isEqualTo("databasechangelog"));
47-
48-
case TABLES_WITH_MISSING_INDEXES -> assertThat(check.check())
49-
.hasSizeLessThanOrEqualTo(1); // TODO skip runtime checks after https://github.com/mfvanek/pg-index-health/issues/456
50-
51-
default -> assertThat(check.check())
36+
checks.stream()
37+
.filter(DatabaseCheckOnHost::isStatic)
38+
.forEach(check -> {
39+
final Predicate<DbObject> skipLiquibaseTables = dbObject -> {
40+
if (dbObject instanceof TableNameAware t) {
41+
return !t.getTableName().equalsIgnoreCase("databasechangelog");
42+
}
43+
return true;
44+
};
45+
final List<? extends DbObject> objects = check.check(PgContext.ofPublic(), skipLiquibaseTables);
46+
assertThat(objects)
5247
.as(check.getDiagnostic().name())
5348
.isEmpty();
54-
}
55-
});
49+
});
5650
}
5751
}

spring-boot-2-demo-app/src/test/java/io/github/mfvanek/spring/boot2/test/support/PostgresInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public class PostgresInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
1212

13-
private static final DockerImageName IMAGE = DockerImageName.parse("postgres:16.4");
13+
private static final DockerImageName IMAGE = DockerImageName.parse("postgres:17.0");
1414
private static final Network NETWORK = Network.newNetwork();
1515
private static final PostgreSQLContainer<?> CONTAINER = new PostgreSQLContainer<>(IMAGE);
1616

spring-boot-3-demo-app/src/test/java/io/github/mfvanek/spring/boot3/test/IndexesMaintenanceTest.java

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnHost;
44
import io.github.mfvanek.pg.common.maintenance.Diagnostic;
55
import io.github.mfvanek.pg.model.DbObject;
6-
import io.github.mfvanek.pg.model.column.Column;
7-
import io.github.mfvanek.pg.model.table.Table;
6+
import io.github.mfvanek.pg.model.PgContext;
7+
import io.github.mfvanek.pg.model.table.TableNameAware;
88
import io.github.mfvanek.spring.boot3.test.support.TestBase;
99
import org.junit.jupiter.api.DisplayName;
1010
import org.junit.jupiter.api.Test;
1111
import org.springframework.beans.factory.annotation.Autowired;
1212

1313
import java.util.List;
14+
import java.util.function.Predicate;
1415

1516
import static org.assertj.core.api.Assertions.assertThat;
16-
import static org.assertj.core.api.InstanceOfAssertFactories.list;
1717

1818
class IndexesMaintenanceTest extends TestBase {
1919

@@ -25,33 +25,27 @@ class IndexesMaintenanceTest extends TestBase {
2525
void checkPostgresVersion() {
2626
final String pgVersion = jdbcTemplate.queryForObject("select version();", String.class);
2727
assertThat(pgVersion)
28-
.startsWith("PostgreSQL 16.4");
28+
.startsWith("PostgreSQL 17.0");
2929
}
3030

3131
@Test
3232
void databaseStructureCheckForPublicSchema() {
3333
assertThat(checks)
3434
.hasSameSizeAs(Diagnostic.values());
3535

36-
checks.forEach(check -> {
37-
switch (check.getDiagnostic()) {
38-
case TABLES_WITHOUT_PRIMARY_KEY, TABLES_WITHOUT_DESCRIPTION -> assertThat(check.check())
39-
.asInstanceOf(list(Table.class))
40-
.hasSize(1)
41-
.containsExactly(Table.of("databasechangelog", 0L));
42-
43-
case COLUMNS_WITHOUT_DESCRIPTION -> assertThat(check.check())
44-
.asInstanceOf(list(Column.class))
45-
.hasSize(14)
46-
.allSatisfy(column -> assertThat(column.getTableName()).isEqualTo("databasechangelog"));
47-
48-
case TABLES_WITH_MISSING_INDEXES -> assertThat(check.check())
49-
.hasSizeLessThanOrEqualTo(1); // TODO skip runtime checks after https://github.com/mfvanek/pg-index-health/issues/456
50-
51-
default -> assertThat(check.check())
36+
checks.stream()
37+
.filter(DatabaseCheckOnHost::isStatic)
38+
.forEach(check -> {
39+
final Predicate<DbObject> skipLiquibaseTables = dbObject -> {
40+
if (dbObject instanceof TableNameAware t) {
41+
return !t.getTableName().equalsIgnoreCase("databasechangelog");
42+
}
43+
return true;
44+
};
45+
final List<? extends DbObject> objects = check.check(PgContext.ofPublic(), skipLiquibaseTables);
46+
assertThat(objects)
5247
.as(check.getDiagnostic().name())
5348
.isEmpty();
54-
}
55-
});
49+
});
5650
}
5751
}

spring-boot-3-demo-app/src/test/java/io/github/mfvanek/spring/boot3/test/support/PostgresInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public class PostgresInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
1212

13-
private static final DockerImageName IMAGE = DockerImageName.parse("postgres:16.4");
13+
private static final DockerImageName IMAGE = DockerImageName.parse("postgres:17.0");
1414
private static final Network NETWORK = Network.newNetwork();
1515
private static final PostgreSQLContainer<?> CONTAINER = new PostgreSQLContainer<>(IMAGE);
1616

0 commit comments

Comments
 (0)