diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index c03dd21c..76170e9c 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -120,7 +120,7 @@ - + diff --git a/config/spotbugs/exclude.xml b/config/spotbugs/exclude.xml index cb4de069..dcf1226c 100644 --- a/config/spotbugs/exclude.xml +++ b/config/spotbugs/exclude.xml @@ -109,4 +109,8 @@ + + + + diff --git a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/Diagnostic.java b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/Diagnostic.java index 27379978..2e32d080 100644 --- a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/Diagnostic.java +++ b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/Diagnostic.java @@ -107,7 +107,7 @@ public enum Diagnostic implements CheckTypeAware { } /** - * Gets the place where the diagnostic should be executed. + * Retrieves the place where the diagnostic should be executed. * * @return {@code ExecutionTopology} */ @@ -117,7 +117,7 @@ public ExecutionTopology getExecutionTopology() { } /** - * Gets the associated sql query file name. + * Retrieves the associated sql query file name. * * @return sql query file name */ @@ -127,7 +127,7 @@ public String getSqlQueryFileName() { } /** - * Gets the lambda which executes the associated sql query. + * Retrieves the lambda which executes the associated sql query. * * @return {@code QueryExecutor} */ diff --git a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/DiagnosticAware.java b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/DiagnosticAware.java index 7a0fc460..905aabb6 100644 --- a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/DiagnosticAware.java +++ b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/DiagnosticAware.java @@ -21,7 +21,7 @@ public interface DiagnosticAware { /** - * Gets the diagnostic - a rule related to the check. + * Retrieves the diagnostic - a rule related to the check. * * @return diagnostic * @see Diagnostic diff --git a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/RawTypeAware.java b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/RawTypeAware.java index cdd728e9..ae387def 100644 --- a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/RawTypeAware.java +++ b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/common/maintenance/RawTypeAware.java @@ -24,7 +24,7 @@ public interface RawTypeAware { /** - * Gets original java type. + * Retrieves original java type. * * @return java type representing database object */ diff --git a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/StatisticsAware.java b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/StatisticsAware.java index 3b159060..19e2dcf9 100644 --- a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/StatisticsAware.java +++ b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/StatisticsAware.java @@ -32,7 +32,7 @@ public interface StatisticsAware { boolean resetStatistics(); /** - * Gets time at which database statistics were last reset. + * Retrieves the time at which database statistics were last reset. * * @return {@code Optional} of null or time at which database statistics were last reset. */ diff --git a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/maintenance/StatisticsMaintenanceOnHost.java b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/maintenance/StatisticsMaintenanceOnHost.java index 36d7d4cd..3cf32161 100644 --- a/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/maintenance/StatisticsMaintenanceOnHost.java +++ b/pg-index-health-core/src/main/java/io/github/mfvanek/pg/statistics/maintenance/StatisticsMaintenanceOnHost.java @@ -37,7 +37,7 @@ public interface StatisticsMaintenanceOnHost extends StatisticsAware, HostAware boolean resetStatistics(); /** - * Gets time at which database statistics were last reset on current host. + * Retrieves the time at which database statistics were last reset on current host. * * @return {@code Optional} of null or time at which database statistics were last reset. */ diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/DuplicatedIndexesCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/DuplicatedIndexesCheckOnHostTest.java index 6e37e45c..dedd0445 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/DuplicatedIndexesCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/DuplicatedIndexesCheckOnHostTest.java @@ -15,6 +15,7 @@ import io.github.mfvanek.pg.model.PgContext; import io.github.mfvanek.pg.model.index.DuplicatedIndexes; import io.github.mfvanek.pg.model.index.IndexWithSize; +import io.github.mfvanek.pg.model.predicates.SkipIndexesByNamePredicate; import io.github.mfvanek.pg.model.predicates.SkipTablesByNamePredicate; import io.github.mfvanek.pg.support.DatabaseAwareTestBase; import org.junit.jupiter.api.Test; @@ -52,6 +53,14 @@ void onDatabaseWithThem(final String schemaName) { assertThat(check) .executing(ctx, SkipTablesByNamePredicate.ofName(ctx, "accounts")) .isEmpty(); + + assertThat(check) + .executing(ctx, SkipIndexesByNamePredicate.ofName(ctx, "accounts_account_number_key")) + .isEmpty(); + + assertThat(check) + .executing(ctx, SkipIndexesByNamePredicate.ofName(ctx, "i_accounts_account_number")) + .isEmpty(); }); } diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/IntersectedIndexesCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/IntersectedIndexesCheckOnHostTest.java index f1c24fc0..755c5dc0 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/IntersectedIndexesCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/checks/host/IntersectedIndexesCheckOnHostTest.java @@ -15,6 +15,7 @@ import io.github.mfvanek.pg.model.PgContext; import io.github.mfvanek.pg.model.index.DuplicatedIndexes; import io.github.mfvanek.pg.model.index.IndexWithSize; +import io.github.mfvanek.pg.model.predicates.SkipIndexesByNamePredicate; import io.github.mfvanek.pg.model.predicates.SkipTablesByNamePredicate; import io.github.mfvanek.pg.support.DatabaseAwareTestBase; import org.junit.jupiter.api.Test; @@ -58,13 +59,17 @@ void onDatabaseWithThem(final String schemaName) { assertThat(check) .executing(ctx, SkipTablesByNamePredicate.of(ctx, List.of("accounts", "clients"))) .isEmpty(); + + assertThat(check) + .executing(ctx, SkipIndexesByNamePredicate.of(ctx, List.of("i_clients_last_first", "i_accounts_number_balance_not_deleted"))) + .isEmpty(); }); } @ParameterizedTest @ValueSource(strings = {PgContext.DEFAULT_SCHEMA_NAME, "custom"}) void shouldFindHashIndex(final String schemaName) { - executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withData().withDuplicatedHashIndex(), ctx -> + executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withData().withDuplicatedHashIndex(), ctx -> { assertThat(check) .executing(ctx) .hasSize(1) @@ -72,7 +77,16 @@ void shouldFindHashIndex(final String schemaName) { DuplicatedIndexes.of( IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_first"), 0L), IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"), 0L))) - .allMatch(d -> d.getTotalSize() >= 106_496L)); + .allMatch(d -> d.getTotalSize() >= 106_496L); + + assertThat(check) + .executing(ctx, SkipIndexesByNamePredicate.ofName(ctx, "i_clients_last_first")) + .isEmpty(); + + assertThat(check) + .executing(ctx, SkipIndexesByNamePredicate.ofName(ctx, "i_clients_last_name")) + .isEmpty(); + }); } @ParameterizedTest diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/ConnectionCredentials.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/ConnectionCredentials.java index ea9986d9..41f9a1f9 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/ConnectionCredentials.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/ConnectionCredentials.java @@ -44,7 +44,7 @@ private ConnectionCredentials(@Nonnull final Collection connectionUrls, } /** - * Gets a set of connection strings for accessing all hosts in the database cluster. + * Retrieves a set of connection strings for accessing all hosts in the database cluster. * * @return connection urls */ @@ -54,7 +54,7 @@ public Collection getConnectionUrls() { } /** - * Gets the name of the user to connect to the database. + * Retrieves the name of the user to connect to the database. * * @return the name of the user */ @@ -64,7 +64,7 @@ public String getUserName() { } /** - * Gets the user's password for connecting to the database. + * Retrieves the user's password for connecting to the database. * * @return the user's password */ diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnection.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnection.java index a2518a70..0fb547bf 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnection.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnection.java @@ -22,7 +22,7 @@ public interface HighAvailabilityPgConnection { /** - * Gets connection to a primary host in the cluster. + * Retrieves connection to a primary host in the cluster. * * @return {@code PgConnection} to a primary host in the cluster */ @@ -30,7 +30,7 @@ public interface HighAvailabilityPgConnection { PgConnection getConnectionToPrimary(); /** - * Gets connections to all hosts in the cluster (including a connection to a primary host). + * Retrieves connections to all hosts in the cluster (including a connection to a primary host). * * @return {@code Set} of connections to all hosts in target cluster */ diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HostAware.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HostAware.java index c1dfca82..c5f91d20 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HostAware.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HostAware.java @@ -20,7 +20,7 @@ public interface HostAware { /** - * Gets information about host in the cluster. + * Retrieves information about host in the cluster. * * @return {@code PgHost} * @see PgHost diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnection.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnection.java index 17026f48..836342c7 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnection.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnection.java @@ -23,7 +23,7 @@ public interface PgConnection extends HostAware { /** - * Gets a standard {@code DataSource} object to access the database. + * Retrieves a standard {@code DataSource} object to access the database. * * @return {@code DataSource} */ diff --git a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgHost.java b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgHost.java index 3d034d7e..e552a9b9 100644 --- a/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgHost.java +++ b/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgHost.java @@ -23,7 +23,7 @@ public interface PgHost { /** - * Gets a valid connection string to this host. + * Retrieves a valid connection string to this host. * * @return connection url to the host */ @@ -31,7 +31,7 @@ public interface PgHost { String getPgUrl(); /** - * Gets the name of this host. + * Retrieves the name of this host. * * @return host name */ @@ -39,7 +39,7 @@ public interface PgHost { String getName(); /** - * Gets the port of this host. + * Retrieves the port of this host. * * @return port */ diff --git a/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/AbstractHealthLogger.java b/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/AbstractHealthLogger.java index 928d881f..4bb869c2 100644 --- a/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/AbstractHealthLogger.java +++ b/pg-index-health-logger/src/main/java/io/github/mfvanek/pg/common/health/logger/AbstractHealthLogger.java @@ -10,7 +10,6 @@ package io.github.mfvanek.pg.common.health.logger; -import io.github.mfvanek.pg.checks.predicates.FilterDuplicatedIndexesByNamePredicate; import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnCluster; import io.github.mfvanek.pg.common.maintenance.DatabaseChecks; import io.github.mfvanek.pg.common.maintenance.Diagnostic; @@ -130,13 +129,13 @@ private String writeZeroToLog(@Nonnull final LoggingKey key) { @Nonnull private String logDuplicatedIndexes(@Nonnull final Exclusions exclusions) { return logCheckResult(databaseChecksHolder.get().getCheck(Diagnostic.DUPLICATED_INDEXES, DuplicatedIndexes.class), - FilterDuplicatedIndexesByNamePredicate.of(exclusions.getDuplicatedIndexesExclusions()), SimpleLoggingKey.DUPLICATED_INDEXES); + SkipIndexesByNamePredicate.of(pgContextHolder.get(), exclusions.getDuplicatedIndexesExclusions()), SimpleLoggingKey.DUPLICATED_INDEXES); } @Nonnull private String logIntersectedIndexes(@Nonnull final Exclusions exclusions) { return logCheckResult(databaseChecksHolder.get().getCheck(Diagnostic.INTERSECTED_INDEXES, DuplicatedIndexes.class), - FilterDuplicatedIndexesByNamePredicate.of(exclusions.getIntersectedIndexesExclusions()), SimpleLoggingKey.INTERSECTED_INDEXES); + SkipIndexesByNamePredicate.of(pgContextHolder.get(), exclusions.getIntersectedIndexesExclusions()), SimpleLoggingKey.INTERSECTED_INDEXES); } @Nonnull diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/BloatAware.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/BloatAware.java index 8380e4da..3e1932a2 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/BloatAware.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/BloatAware.java @@ -18,14 +18,14 @@ public interface BloatAware { /** - * Gets bloat amount in bytes. + * Retrieves bloat amount in bytes. * * @return bloat amount */ long getBloatSizeInBytes(); /** - * Gets bloat percentage (in the range from 0 to 100 inclusive). + * Retrieves bloat percentage (in the range from 0 to 100 inclusive). * * @return bloat percentage */ diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/DbObject.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/DbObject.java index e7dc7be7..4f3fc7bf 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/DbObject.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/DbObject.java @@ -24,7 +24,7 @@ public interface DbObject { /** - * Gets database object name. + * Retrieves database object name. * * @return database object name */ @@ -32,7 +32,7 @@ public interface DbObject { String getName(); /** - * Gets database object type. + * Retrieves database object type. * * @return database object type * @since 0.13.2 diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/ColumnNameAware.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/ColumnNameAware.java index f4320ba5..eace9ab8 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/ColumnNameAware.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/ColumnNameAware.java @@ -24,7 +24,7 @@ public interface ColumnNameAware extends TableNameAware { /** - * Gets column name in the table. + * Retrieves column name in the table. * * @return column name */ diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/ColumnWithSerialType.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/ColumnWithSerialType.java index a7ddfc5d..74958c2f 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/ColumnWithSerialType.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/ColumnWithSerialType.java @@ -87,7 +87,7 @@ public boolean isNotNull() { } /** - * Gets raw type of serial column. + * Retrieves raw type of serial column. * * @return type of serial column */ @@ -97,7 +97,7 @@ public SerialType getSerialType() { } /** - * Gets name of the associated sequence. + * Retrieves name of the associated sequence. * * @return name of the associated sequence */ diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/SerialType.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/SerialType.java index 8d2295ce..af3c8d53 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/SerialType.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/SerialType.java @@ -74,7 +74,7 @@ public String toString() { } /** - * Gets {@code SerialType} from PostgreSQL serial column type. + * Retrieves {@code SerialType} from PostgreSQL serial column type. * * @param pgColumnType PostgreSQL serial column type; should be non-null. * @return {@code SerialType} diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/Constraint.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/Constraint.java index 2809a44f..c2541213 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/Constraint.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/Constraint.java @@ -28,7 +28,7 @@ * @since 0.11.0 */ @Immutable -public class Constraint implements DbObject, TableNameAware { +public class Constraint implements DbObject, TableNameAware, ConstraintNameAware { private final String tableName; private final String constraintName; @@ -78,17 +78,16 @@ public String getTableName() { } /** - * Gets the name of constraint. - * - * @return the name of constraint + * {@inheritDoc} */ @Nonnull + @Override public String getConstraintName() { return constraintName; } /** - * Gets type of constraint. + * Retrieves type of constraint. * * @return type of constraint * @see ConstraintType diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ConstraintNameAware.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ConstraintNameAware.java new file mode 100644 index 00000000..a8871542 --- /dev/null +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ConstraintNameAware.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * https://github.com/mfvanek/pg-index-health + * + * This file is a part of "pg-index-health" - a Java library for + * analyzing and maintaining indexes health in PostgreSQL databases. + * + * Licensed under the Apache License 2.0 + */ + +package io.github.mfvanek.pg.model.constraint; + +import javax.annotation.Nonnull; + +/** + * Represents an entity that is aware of a database constraint name. + * Classes implementing this interface should provide the name of a specific database constraint. + * + * @author Ivan Vakhrushev + * @since 0.13.3 + */ +public interface ConstraintNameAware { + + /** + * Retrieves the name of the database constraint associated with this entity. + * + * @return the name of the constraint as a non-null {@link String}. + */ + @Nonnull + String getConstraintName(); +} diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ConstraintType.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ConstraintType.java index a6b0091a..760942f9 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ConstraintType.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ConstraintType.java @@ -38,7 +38,7 @@ public enum ConstraintType { } /** - * Gets internal PostgreSQL constraint type. + * Retrieves internal PostgreSQL constraint type. * * @return pgConType */ @@ -48,7 +48,7 @@ public String getPgConType() { } /** - * Gets {@code ConstraintType} from internal PostgreSQL constraint type. + * Retrieves {@code ConstraintType} from internal PostgreSQL constraint type. * * @param pgConType internal PostgreSQL constraint type; should be non-null. * @return {@code ConstraintType} diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ConstraintsAware.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ConstraintsAware.java new file mode 100644 index 00000000..25ee5660 --- /dev/null +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ConstraintsAware.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * https://github.com/mfvanek/pg-index-health + * + * This file is a part of "pg-index-health" - a Java library for + * analyzing and maintaining indexes health in PostgreSQL databases. + * + * Licensed under the Apache License 2.0 + */ + +package io.github.mfvanek.pg.model.constraint; + +import java.util.List; +import javax.annotation.Nonnull; + +/** + * Represents an entity that is aware of database constraints. + * Classes implementing this interface should provide access to a list of associated constraints. + * + * @author Ivan Vakhrushev + * @since 0.13.3 + */ +public interface ConstraintsAware { + + /** + * Retrieves the list of database constraints associated with this entity. + * + * @return a list of {@link Constraint} objects. The list may be empty but will never be {@code null}. + */ + @Nonnull + List getConstraints(); +} diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/DuplicatedForeignKeys.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/DuplicatedForeignKeys.java index df8eaa87..30984d52 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/DuplicatedForeignKeys.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/DuplicatedForeignKeys.java @@ -30,7 +30,7 @@ * @since 0.13.1 */ @Immutable -public class DuplicatedForeignKeys implements DbObject, TableNameAware { +public class DuplicatedForeignKeys implements DbObject, TableNameAware, ConstraintsAware { private final List foreignKeys; private final List foreignKeysNames; @@ -72,7 +72,7 @@ public String getTableName() { } /** - * Gets duplicated foreign keys. + * Retrieves duplicated foreign keys. * * @return list of duplicated foreign keys * @see ForeignKey @@ -82,6 +82,15 @@ public List getForeignKeys() { return foreignKeys; } + /** + * {@inheritDoc} + */ + @Override + @Nonnull + public List getConstraints() { + return List.copyOf(getForeignKeys()); + } + /** * {@inheritDoc} */ diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ForeignKey.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ForeignKey.java index 417e5213..774598f2 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ForeignKey.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ForeignKey.java @@ -42,7 +42,7 @@ private ForeignKey(@Nonnull final String tableName, } /** - * Gets columns of foreign key constraint. + * Retrieves columns of foreign key constraint. * * @return columns of foreign key constraint * @see Column diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/function/StoredFunction.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/function/StoredFunction.java index 3800e817..8d922a14 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/function/StoredFunction.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/function/StoredFunction.java @@ -55,7 +55,7 @@ public final PgObjectType getObjectType() { } /** - * Gets procedure/function name. + * Retrieves procedure/function name. * * @return returns procedure/function name */ @@ -65,7 +65,7 @@ public String getFunctionName() { } /** - * Gets procedure/function arguments. + * Retrieves procedure/function arguments. * * @return returns procedure/function arguments or empty string */ diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/DuplicatedIndexes.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/DuplicatedIndexes.java index 76630c76..d452242c 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/DuplicatedIndexes.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/DuplicatedIndexes.java @@ -31,7 +31,7 @@ * @see TableNameAware */ @Immutable -public class DuplicatedIndexes implements DbObject, TableNameAware { +public class DuplicatedIndexes implements DbObject, TableNameAware, IndexesAware { private static final Comparator INDEX_WITH_SIZE_COMPARATOR = Comparator.comparing(IndexWithSize::getTableName) @@ -84,7 +84,7 @@ public String getTableName() { } /** - * Gets raw list of duplicated indexes. + * Retrieves raw list of duplicated indexes. * * @return list of duplicated indexes */ @@ -94,7 +94,16 @@ public List getDuplicatedIndexes() { } /** - * Gets total size in bytes of all duplicated indexes. + * {@inheritDoc} + */ + @Nonnull + @Override + public List getIndexes() { + return List.copyOf(indexes); + } + + /** + * Retrieves total size in bytes of all duplicated indexes. * * @return size in bytes */ @@ -103,7 +112,7 @@ public long getTotalSize() { } /** - * Gets names of all duplicated indexes. + * Retrieves names of all duplicated indexes. * * @return sorted list */ diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexNameAware.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexNameAware.java index 3fae81c5..012049a7 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexNameAware.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexNameAware.java @@ -21,7 +21,7 @@ public interface IndexNameAware { /** - * Gets index name. + * Retrieves index name. * * @return index name */ diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexSizeAware.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexSizeAware.java index 7fa55d53..488a4b33 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexSizeAware.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexSizeAware.java @@ -21,7 +21,7 @@ public interface IndexSizeAware extends IndexNameAware { /** - * Gets index size in bytes. + * Retrieves index size in bytes. * * @return index size in bytes */ diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithColumns.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithColumns.java index 88904595..5b3c6b45 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithColumns.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithColumns.java @@ -49,7 +49,7 @@ protected IndexWithColumns(@Nonnull final String tableName, } /** - * Gets columns in index. + * Retrieves columns in index. * * @return list of columns */ diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithNulls.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithNulls.java index 43d3adad..382d5c7e 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithNulls.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexWithNulls.java @@ -34,7 +34,7 @@ private IndexWithNulls(@Nonnull final String tableName, } /** - * Gets nullable column in index. + * Retrieves nullable column in index. * * @return nullable column */ diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexesAware.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexesAware.java new file mode 100644 index 00000000..797f4a74 --- /dev/null +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexesAware.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2019-2024. Ivan Vakhrushev and others. + * https://github.com/mfvanek/pg-index-health + * + * This file is a part of "pg-index-health" - a Java library for + * analyzing and maintaining indexes health in PostgreSQL databases. + * + * Licensed under the Apache License 2.0 + */ + +package io.github.mfvanek.pg.model.index; + +import java.util.List; +import javax.annotation.Nonnull; + +/** + * Represents an entity that is aware of and can provide a list of indexes. + * Classes implementing this interface should return a list of objects that extend {@link Index}. + * + * @author Ivan Vakhrushev + * @see Index + * @since 0.13.3 + */ +public interface IndexesAware { + + /** + * Retrieves a list of indexes associated with this entity. + * + * @return a non-null list of {@link Index} or its subclasses. The list may be empty if no indexes are available. + */ + @Nonnull + List getIndexes(); +} diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/object/PgObjectType.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/object/PgObjectType.java index f2c6c36a..58a77311 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/object/PgObjectType.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/object/PgObjectType.java @@ -75,7 +75,7 @@ public enum PgObjectType { } /** - * Gets {@code PgObjectType} from given literal representation. + * Retrieves {@code PgObjectType} from given literal representation. * * @param objectType literal PostgreSQL object type; should be non-null. * @return {@code PgObjectType} diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/predicates/SkipIndexesByNamePredicate.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/predicates/SkipIndexesByNamePredicate.java index c56f241c..eb230e84 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/predicates/SkipIndexesByNamePredicate.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/predicates/SkipIndexesByNamePredicate.java @@ -12,7 +12,9 @@ import io.github.mfvanek.pg.model.DbObject; import io.github.mfvanek.pg.model.PgContext; +import io.github.mfvanek.pg.model.index.Index; import io.github.mfvanek.pg.model.index.IndexNameAware; +import io.github.mfvanek.pg.model.index.IndexesAware; import java.util.Collection; import java.util.Locale; @@ -60,10 +62,21 @@ private SkipIndexesByNamePredicate(@Nonnull final PgContext pgContext, @Nonnull */ @Override public boolean test(@Nonnull final DbObject dbObject) { - if (!fullyQualifiedIndexNamesToSkip.isEmpty() && dbObject instanceof IndexNameAware) { + if (fullyQualifiedIndexNamesToSkip.isEmpty()) { + return true; + } + if (dbObject instanceof IndexNameAware) { final IndexNameAware i = (IndexNameAware) dbObject; return !fullyQualifiedIndexNamesToSkip.contains(i.getIndexName().toLowerCase(Locale.ROOT)); } + if (dbObject instanceof IndexesAware) { + final IndexesAware i = (IndexesAware) dbObject; + for (final Index index : i.getIndexes()) { + if (fullyQualifiedIndexNamesToSkip.contains(index.getIndexName().toLowerCase(Locale.ROOT))) { + return false; + } + } + } return true; } diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableNameAware.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableNameAware.java index 2c0991c8..6711fca2 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableNameAware.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableNameAware.java @@ -21,7 +21,7 @@ public interface TableNameAware { /** - * Gets table name. + * Retrieves table name. * * @return table name */ diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableSizeAware.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableSizeAware.java index 9903916b..a65747ce 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableSizeAware.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableSizeAware.java @@ -21,7 +21,7 @@ public interface TableSizeAware extends TableNameAware { /** - * Gets table size in bytes. + * Retrieves table size in bytes. * * @return table size in bytes */ diff --git a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableWithMissingIndex.java b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableWithMissingIndex.java index 438f6520..8a85b244 100644 --- a/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableWithMissingIndex.java +++ b/pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableWithMissingIndex.java @@ -45,7 +45,7 @@ private TableWithMissingIndex(@Nonnull final Table table, } /** - * Gets the number of sequential scans performed on this table. + * Retrieves the number of sequential scans performed on this table. * * @return the sequential scan count */ @@ -54,7 +54,7 @@ public long getSeqScans() { } /** - * Gets the number of index scans performed on this table. + * Retrieves the number of index scans performed on this table. * * @return the index scan count */ diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/constraint/DuplicatedForeignKeysTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/constraint/DuplicatedForeignKeysTest.java index 652359e6..a2443ceb 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/constraint/DuplicatedForeignKeysTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/constraint/DuplicatedForeignKeysTest.java @@ -48,6 +48,9 @@ void internalCollectionShouldBeUnmodifiable() { assertThat(foreignKeys.getForeignKeys()) .hasSize(2) .isUnmodifiable(); + assertThat(foreignKeys.getConstraints()) + .hasSize(2) + .isUnmodifiable(); } @SuppressWarnings("DataFlowIssue") diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/DuplicatedIndexesTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/DuplicatedIndexesTest.java index 7b957986..4855e21a 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/DuplicatedIndexesTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/index/DuplicatedIndexesTest.java @@ -78,6 +78,11 @@ void shouldCreateDefensiveCopyOfIndexesList() { .doesNotContain(fourth) .isUnmodifiable(); + assertThat(indexes.getIndexes()) + .hasSize(3) + .doesNotContain(fourth) + .isUnmodifiable(); + assertThat(indexes.getIndexNames()) .hasSize(3) .doesNotContain("i4") diff --git a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipIndexesByNamePredicateTest.java b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipIndexesByNamePredicateTest.java index 9e19e864..76827b2b 100644 --- a/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipIndexesByNamePredicateTest.java +++ b/pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/predicates/SkipIndexesByNamePredicateTest.java @@ -13,7 +13,9 @@ import io.github.mfvanek.pg.model.PgContext; import io.github.mfvanek.pg.model.column.Column; import io.github.mfvanek.pg.model.column.ColumnWithSerialType; +import io.github.mfvanek.pg.model.index.DuplicatedIndexes; import io.github.mfvanek.pg.model.index.Index; +import io.github.mfvanek.pg.model.index.IndexWithSize; import io.github.mfvanek.pg.model.sequence.SequenceState; import io.github.mfvanek.pg.model.table.Table; import org.junit.jupiter.api.Test; @@ -83,15 +85,27 @@ void shouldWorkForSingleIndex() { assertThat(SkipIndexesByNamePredicate.ofName("i2")) .accepts(Table.of("t", 0L)) .accepts(Index.of("t1", "i1")) + .accepts(DuplicatedIndexes.of( + IndexWithSize.of("t1", "i1", 1L), + IndexWithSize.of("t1", "i3", 1L))) .rejects(Index.of("t2", "i2")) - .rejects(Index.of("t2", "I2")); + .rejects(Index.of("t2", "I2")) + .rejects(DuplicatedIndexes.of( + IndexWithSize.of("t1", "i1", 1L), + IndexWithSize.of("t1", "i2", 1L))); final PgContext ctx = PgContext.of("CUSTOM"); assertThat(SkipIndexesByNamePredicate.ofName(ctx, "I2")) .accepts(Table.of("custom.t", 0L)) .accepts(Index.of("custom.t1", "custom.i1")) + .accepts(DuplicatedIndexes.of( + IndexWithSize.of("custom.t1", "custom.i1", 1L), + IndexWithSize.of("custom.t1", "custom.i3", 1L))) .rejects(Index.of("custom.t2", "custom.i2")) - .rejects(Index.of("custom.T2", "custom.I2")); + .rejects(Index.of("custom.T2", "custom.I2")) + .rejects(DuplicatedIndexes.of( + IndexWithSize.of("custom.t1", "custom.i1", 1L), + IndexWithSize.of("custom.t1", "custom.i2", 1L))); } @Test @@ -100,9 +114,15 @@ void shouldWorkForMultipleIndexes() { .accepts(Table.of("t", 0L)) .accepts(SequenceState.of("s11", "int", 80.0)) .accepts(ColumnWithSerialType.ofSerial(Column.ofNullable("t", "c"), "s1")) + .accepts(DuplicatedIndexes.of( + IndexWithSize.of("t1", "i", 1L), + IndexWithSize.of("t1", "i3", 1L))) .rejects(Index.of("t1", "i1")) .rejects(Index.of("t2", "i1")) - .rejects(Index.of("T2", "I2")); + .rejects(Index.of("T2", "I2")) + .rejects(DuplicatedIndexes.of( + IndexWithSize.of("t1", "i1", 1L), + IndexWithSize.of("t1", "i2", 1L))); } @ParameterizedTest diff --git a/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgresVersionHolder.java b/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgresVersionHolder.java index b1525527..c7ee9e7b 100644 --- a/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgresVersionHolder.java +++ b/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgresVersionHolder.java @@ -36,7 +36,7 @@ private int getMajorVersion() { } /** - * Gets target PostgreSQL version to run with Testcontainers. + * Retrieves target PostgreSQL version to run with Testcontainers. * * @return PostgreSQL version to run */ diff --git a/pg-index-health/src/main/java/io/github/mfvanek/pg/checks/predicates/FilterDuplicatedIndexesByNamePredicate.java b/pg-index-health/src/main/java/io/github/mfvanek/pg/checks/predicates/FilterDuplicatedIndexesByNamePredicate.java index 245a7acd..79206238 100644 --- a/pg-index-health/src/main/java/io/github/mfvanek/pg/checks/predicates/FilterDuplicatedIndexesByNamePredicate.java +++ b/pg-index-health/src/main/java/io/github/mfvanek/pg/checks/predicates/FilterDuplicatedIndexesByNamePredicate.java @@ -22,7 +22,9 @@ * * @author Ivan Vakhrushev * @since 0.6.0 + * @deprecated This class has been replaced by {@link io.github.mfvanek.pg.model.predicates.SkipIndexesByNamePredicate} */ +@Deprecated(since = "0.13.3", forRemoval = true) public class FilterDuplicatedIndexesByNamePredicate extends AbstractFilterByName implements Predicate { private FilterDuplicatedIndexesByNamePredicate(@Nonnull final Collection exclusions) { diff --git a/pg-index-health/src/main/java/io/github/mfvanek/pg/common/management/DatabaseManagement.java b/pg-index-health/src/main/java/io/github/mfvanek/pg/common/management/DatabaseManagement.java index a86e3bed..b2f132e7 100644 --- a/pg-index-health/src/main/java/io/github/mfvanek/pg/common/management/DatabaseManagement.java +++ b/pg-index-health/src/main/java/io/github/mfvanek/pg/common/management/DatabaseManagement.java @@ -33,7 +33,7 @@ public interface DatabaseManagement extends StatisticsAware, ConfigurationAware boolean resetStatistics(); /** - * Gets time at which database statistics were last reset on the primary host. + * Retrieves the time at which database statistics were last reset on the primary host. * * @return {@code Optional} of null or time at which database statistics were last reset. */ diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/DuplicatedIndexesCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/DuplicatedIndexesCheckOnClusterTest.java index 42b79f16..e4aad161 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/DuplicatedIndexesCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/DuplicatedIndexesCheckOnClusterTest.java @@ -10,12 +10,12 @@ package io.github.mfvanek.pg.checks.cluster; -import io.github.mfvanek.pg.checks.predicates.FilterDuplicatedIndexesByNamePredicate; import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnCluster; import io.github.mfvanek.pg.common.maintenance.Diagnostic; import io.github.mfvanek.pg.model.PgContext; import io.github.mfvanek.pg.model.index.DuplicatedIndexes; import io.github.mfvanek.pg.model.index.IndexWithSize; +import io.github.mfvanek.pg.model.predicates.SkipIndexesByNamePredicate; import io.github.mfvanek.pg.model.predicates.SkipTablesByNamePredicate; import io.github.mfvanek.pg.support.DatabaseAwareTestBase; import org.junit.jupiter.api.Test; @@ -54,11 +54,11 @@ void onDatabaseWithThem(final String schemaName) { .isEmpty(); assertThat(check) - .executing(ctx, FilterDuplicatedIndexesByNamePredicate.of(ctx.enrichWithSchema("accounts_account_number_key"))) + .executing(ctx, SkipIndexesByNamePredicate.ofName(ctx, "accounts_account_number_key")) .isEmpty(); assertThat(check) - .executing(ctx, FilterDuplicatedIndexesByNamePredicate.of(ctx.enrichWithSchema("i_accounts_account_number"))) + .executing(ctx, SkipIndexesByNamePredicate.ofName(ctx, "i_accounts_account_number")) .isEmpty(); }); } diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/IntersectedIndexesCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/IntersectedIndexesCheckOnClusterTest.java index 31a53599..ce6a7885 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/IntersectedIndexesCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/checks/cluster/IntersectedIndexesCheckOnClusterTest.java @@ -10,19 +10,19 @@ package io.github.mfvanek.pg.checks.cluster; -import io.github.mfvanek.pg.checks.predicates.FilterDuplicatedIndexesByNamePredicate; import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnCluster; import io.github.mfvanek.pg.common.maintenance.Diagnostic; import io.github.mfvanek.pg.model.PgContext; import io.github.mfvanek.pg.model.index.DuplicatedIndexes; import io.github.mfvanek.pg.model.index.IndexWithSize; +import io.github.mfvanek.pg.model.predicates.SkipIndexesByNamePredicate; +import io.github.mfvanek.pg.model.predicates.SkipTablesByNamePredicate; import io.github.mfvanek.pg.support.DatabaseAwareTestBase; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import java.util.List; -import java.util.function.Predicate; import static io.github.mfvanek.pg.support.AbstractCheckOnClusterAssert.assertThat; @@ -55,10 +55,12 @@ void onDatabaseWithThem(final String schemaName) { IndexWithSize.of(ctx.enrichWithSchema("clients"), ctx.enrichWithSchema("i_clients_last_name"), 0L))) .allMatch(d -> d.getTotalSize() >= 106_496L); - final Predicate predicate = FilterDuplicatedIndexesByNamePredicate.of( - List.of(ctx.enrichWithSchema("i_clients_last_first"), ctx.enrichWithSchema("i_accounts_number_balance_not_deleted"))); assertThat(check) - .executing(ctx, predicate) + .executing(ctx, SkipTablesByNamePredicate.of(ctx, List.of("accounts", "clients"))) + .isEmpty(); + + assertThat(check) + .executing(ctx, SkipIndexesByNamePredicate.of(ctx, List.of("i_clients_last_first", "i_accounts_number_balance_not_deleted"))) .isEmpty(); }); } @@ -77,11 +79,11 @@ void shouldFindHashIndex(final String schemaName) { .allMatch(d -> d.getTotalSize() >= 106_496L); assertThat(check) - .executing(ctx, FilterDuplicatedIndexesByNamePredicate.of(ctx.enrichWithSchema("i_clients_last_first"))) + .executing(ctx, SkipIndexesByNamePredicate.ofName(ctx, "i_clients_last_first")) .isEmpty(); assertThat(check) - .executing(ctx, FilterDuplicatedIndexesByNamePredicate.of(ctx.enrichWithSchema("i_clients_last_name"))) + .executing(ctx, SkipIndexesByNamePredicate.ofName(ctx, "i_clients_last_name")) .isEmpty(); }); } diff --git a/spring-boot-integration/pg-index-health-test-starter/src/main/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthProperties.java b/spring-boot-integration/pg-index-health-test-starter/src/main/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthProperties.java index 37f84ca9..e2e30a7d 100644 --- a/spring-boot-integration/pg-index-health-test-starter/src/main/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthProperties.java +++ b/spring-boot-integration/pg-index-health-test-starter/src/main/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthProperties.java @@ -39,7 +39,7 @@ public DatabaseStructureHealthProperties(@DefaultValue("true") final boolean ena } /** - * Gets the state of autoconfiguration: enabled or disabled. + * Retrieves the state of autoconfiguration: enabled or disabled. * * @return true if starter enabled otherwise false */