diff --git a/README.md b/README.md index e6d4e26b..86395ea9 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,8 @@ All checks can be divided into 2 groups: | 4 | Unused indexes | **runtime** | no | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/unused_indexes.sql) | | 5 | Foreign keys without associated indexes | static | no | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/foreign_keys_without_index.sql) | | 6 | Indexes with null values | static | no | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/indexes_with_null_values.sql) | -| 7 | Tables with missing indexes | **runtime** | no | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/tables_with_missing_indexes.sql) | -| 8 | Tables without primary key | static | no | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/tables_without_primary_key.sql) | +| 7 | Tables with missing indexes | **runtime** | yes | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/tables_with_missing_indexes.sql) | +| 8 | Tables without primary key | static | yes | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/tables_without_primary_key.sql) | | 9 | Indexes [bloat](https://www.percona.com/blog/2018/08/06/basic-understanding-bloat-vacuum-postgresql-mvcc/) | **runtime** | no | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/bloated_indexes.sql) | | 10 | Tables [bloat](https://www.percona.com/blog/2018/08/06/basic-understanding-bloat-vacuum-postgresql-mvcc/) | **runtime** | no | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/bloated_tables.sql) | | 11 | Tables without [description](https://www.postgresql.org/docs/current/sql-comment.html) | static | yes | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/tables_without_description.sql) | @@ -71,7 +71,7 @@ All checks can be divided into 2 groups: | 21 | Duplicated ([completely identical](https://habr.com/ru/articles/803841/)) foreign keys | static | no | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/duplicated_foreign_keys.sql) | | 22 | Intersected ([partially identical](https://habr.com/ru/articles/803841/)) foreign keys | static | no | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/intersected_foreign_keys.sql) | | 23 | Possible object name overflow (identifiers with maximum length) | static | no | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/possible_object_name_overflow.sql) | -| 24 | Tables not linked to other tables | static | no | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/tables_not_linked_to_others.sql) | +| 24 | Tables not linked to other tables | static | yes | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/tables_not_linked_to_others.sql) | | 25 | Foreign keys [with unmatched column type](https://habr.com/ru/articles/803841/) | static | no | [sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/foreign_keys_with_unmatched_column_type.sql) | For raw sql queries see [pg-index-health-sql](https://github.com/mfvanek/pg-index-health-sql) project. diff --git a/pg-index-health-core/src/main/resources b/pg-index-health-core/src/main/resources index 66239168..e9b0afef 160000 --- a/pg-index-health-core/src/main/resources +++ b/pg-index-health-core/src/main/resources @@ -1 +1 @@ -Subproject commit 66239168f6c8cd4f40d1f306bedc251c8c3b738d +Subproject commit e9b0afef7bf61f614122aeabe16a357158c4303a diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesNotLinkedToOthersCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesNotLinkedToOthersCheckOnHostTest.java index e8c1f803..772b6ecc 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesNotLinkedToOthersCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesNotLinkedToOthersCheckOnHostTest.java @@ -49,4 +49,15 @@ void onDatabaseWithThem(final String schemaName) { .isEmpty(); }); } + + @ParameterizedTest + @ValueSource(strings = {PgContext.DEFAULT_SCHEMA_NAME, "custom"}) + void shouldWorkWithPartitionedTables(final String schemaName) { + executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withPartitionedTableWithoutComments(), ctx -> + assertThat(check) + .executing(ctx) + .hasSize(1) + .containsExactly( + Table.of(ctx, "custom_entity_reference_with_very_very_very_long_name"))); + } } diff --git a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithoutPrimaryKeyCheckOnHostTest.java b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithoutPrimaryKeyCheckOnHostTest.java index 38b8d645..d7822916 100644 --- a/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithoutPrimaryKeyCheckOnHostTest.java +++ b/pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/host/TablesWithoutPrimaryKeyCheckOnHostTest.java @@ -38,7 +38,7 @@ void shouldSatisfyContract() { @ParameterizedTest @ValueSource(strings = {PgContext.DEFAULT_SCHEMA_NAME, "custom"}) void onDatabaseWithThem(final String schemaName) { - executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withData().withTableWithoutPrimaryKey().withIdentityPrimaryKey(), ctx -> { + executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withTableWithoutPrimaryKey().withIdentityPrimaryKey(), ctx -> { assertThat(check) .executing(ctx) .hasSize(1) @@ -53,9 +53,33 @@ void onDatabaseWithThem(final String schemaName) { @ParameterizedTest @ValueSource(strings = {PgContext.DEFAULT_SCHEMA_NAME, "custom"}) void shouldReturnNothingForMaterializedViews(final String schemaName) { - executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withData().withMaterializedView(), ctx -> + executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withMaterializedView(), ctx -> assertThat(check) .executing(ctx) .isEmpty()); } + + @ParameterizedTest + @ValueSource(strings = {PgContext.DEFAULT_SCHEMA_NAME, "custom"}) + void shouldWorkWithPartitionedTablesAndPartitions(final String schemaName) { + executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withPartitionedTableWithoutPrimaryKey(), ctx -> + assertThat(check) + .executing(ctx) + .hasSize(2) + .containsExactly( + Table.of(ctx, "custom_entity_reference_with_very_very_very_long_name"), + Table.of(ctx, "custom_entity_reference_with_very_very_very_long_name_1_default") + )); + } + + @ParameterizedTest + @ValueSource(strings = {PgContext.DEFAULT_SCHEMA_NAME, "custom"}) + void shouldWorkWithPartitionedTablesWhenOnlyPartitionsHavePrimaryKeys(final String schemaName) { + executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withPartitionedTableWithoutPrimaryKey().withPrimaryKeyForDefaultPartition(), ctx -> + assertThat(check) + .executing(ctx) + .hasSize(1) + .containsExactly( + Table.of(ctx, "custom_entity_reference_with_very_very_very_long_name"))); + } } diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/DatabasePopulator.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/DatabasePopulator.java index b13224be..78cb427c 100644 --- a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/DatabasePopulator.java +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/DatabasePopulator.java @@ -21,6 +21,7 @@ import io.github.mfvanek.pg.core.fixtures.support.statements.AddIntersectedForeignKeysStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.AddInvalidForeignKeyStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.AddLinksBetweenAccountsAndClientsStatement; +import io.github.mfvanek.pg.core.fixtures.support.statements.AddPrimaryKeyForDefaultPartitionStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.ConvertColumnToJsonTypeStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.CreateAccountsTableStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.CreateClientsTableStatement; @@ -30,22 +31,23 @@ import io.github.mfvanek.pg.core.fixtures.support.statements.CreateDuplicatedIndexStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.CreateForeignKeyOnNullableColumnStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.CreateFunctionsStatement; -import io.github.mfvanek.pg.core.fixtures.support.statements.CreateIndexWithBooleanValues; -import io.github.mfvanek.pg.core.fixtures.support.statements.CreateIndexWithNullValues; -import io.github.mfvanek.pg.core.fixtures.support.statements.CreateIndexesOnArrayColumn; +import io.github.mfvanek.pg.core.fixtures.support.statements.CreateIndexWithBooleanValuesStatement; +import io.github.mfvanek.pg.core.fixtures.support.statements.CreateIndexWithNullValuesStatement; +import io.github.mfvanek.pg.core.fixtures.support.statements.CreateIndexesOnArrayColumnStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.CreateIndexesWithDifferentOpclassStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.CreateMaterializedViewStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.CreateNotSuitableIndexForForeignKeyStatement; -import io.github.mfvanek.pg.core.fixtures.support.statements.CreatePartitionedTableWithoutComments; +import io.github.mfvanek.pg.core.fixtures.support.statements.CreatePartitionedTableWithoutCommentsStatement; +import io.github.mfvanek.pg.core.fixtures.support.statements.CreatePartitionedTableWithoutPrimaryKeyStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.CreateProceduresStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.CreateSchemaStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.CreateSequenceStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.CreateSuitableIndexForForeignKeyStatement; -import io.github.mfvanek.pg.core.fixtures.support.statements.CreateTableWithCheckConstraintOnSerialPrimaryKey; +import io.github.mfvanek.pg.core.fixtures.support.statements.CreateTableWithCheckConstraintOnSerialPrimaryKeyStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.CreateTableWithColumnOfBigSerialTypeStatement; -import io.github.mfvanek.pg.core.fixtures.support.statements.CreateTableWithIdentityPrimaryKey; -import io.github.mfvanek.pg.core.fixtures.support.statements.CreateTableWithSerialPrimaryKeyReferencesToAnotherTable; -import io.github.mfvanek.pg.core.fixtures.support.statements.CreateTableWithUniqueSerialColumn; +import io.github.mfvanek.pg.core.fixtures.support.statements.CreateTableWithIdentityPrimaryKeyStatement; +import io.github.mfvanek.pg.core.fixtures.support.statements.CreateTableWithSerialPrimaryKeyReferencesToAnotherTableStatement; +import io.github.mfvanek.pg.core.fixtures.support.statements.CreateTableWithUniqueSerialColumnStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.CreateTableWithoutPrimaryKeyStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.DbStatement; import io.github.mfvanek.pg.core.fixtures.support.statements.DropColumnStatement; @@ -140,13 +142,13 @@ public DatabasePopulator withTableWithoutPrimaryKey() { @Nonnull public DatabasePopulator withNullValuesInIndex() { - statementsToExecuteInSameTransaction.putIfAbsent(48, new CreateIndexWithNullValues()); + statementsToExecuteInSameTransaction.putIfAbsent(48, new CreateIndexWithNullValuesStatement()); return this; } @Nonnull public DatabasePopulator withBooleanValuesInIndex() { - statementsToExecuteInSameTransaction.putIfAbsent(49, new CreateIndexWithBooleanValues()); + statementsToExecuteInSameTransaction.putIfAbsent(49, new CreateIndexWithBooleanValuesStatement()); return this; } @@ -224,19 +226,19 @@ public DatabasePopulator withDroppedSerialColumn() { @Nonnull public DatabasePopulator withCheckConstraintOnSerialPrimaryKey() { - statementsToExecuteInSameTransaction.putIfAbsent(80, new CreateTableWithCheckConstraintOnSerialPrimaryKey()); + statementsToExecuteInSameTransaction.putIfAbsent(80, new CreateTableWithCheckConstraintOnSerialPrimaryKeyStatement()); return this; } @Nonnull public DatabasePopulator withUniqueConstraintOnSerialColumn() { - statementsToExecuteInSameTransaction.putIfAbsent(81, new CreateTableWithUniqueSerialColumn()); + statementsToExecuteInSameTransaction.putIfAbsent(81, new CreateTableWithUniqueSerialColumnStatement()); return this; } @Nonnull public DatabasePopulator withSerialPrimaryKeyReferencesToAnotherTable() { - statementsToExecuteInSameTransaction.putIfAbsent(82, new CreateTableWithSerialPrimaryKeyReferencesToAnotherTable()); + statementsToExecuteInSameTransaction.putIfAbsent(82, new CreateTableWithSerialPrimaryKeyReferencesToAnotherTableStatement()); return withCheckConstraintOnSerialPrimaryKey() .withUniqueConstraintOnSerialColumn(); } @@ -282,7 +284,7 @@ public DatabasePopulator withNotValidConstraints() { } public DatabasePopulator withBtreeIndexesOnArrayColumn() { - statementsToExecuteInSameTransaction.putIfAbsent(96, new CreateIndexesOnArrayColumn()); + statementsToExecuteInSameTransaction.putIfAbsent(96, new CreateIndexesOnArrayColumnStatement()); return this; } @@ -294,7 +296,7 @@ public DatabasePopulator withSequenceOverflow() { @Nonnull public DatabasePopulator withIdentityPrimaryKey() { - statementsToExecuteInSameTransaction.putIfAbsent(98, new CreateTableWithIdentityPrimaryKey()); + statementsToExecuteInSameTransaction.putIfAbsent(98, new CreateTableWithIdentityPrimaryKeyStatement()); return this; } @@ -312,7 +314,19 @@ public DatabasePopulator withIntersectedForeignKeys() { @Nonnull public DatabasePopulator withPartitionedTableWithoutComments() { - statementsToExecuteInSameTransaction.putIfAbsent(110, new CreatePartitionedTableWithoutComments()); + statementsToExecuteInSameTransaction.putIfAbsent(110, new CreatePartitionedTableWithoutCommentsStatement()); + return this; + } + + @Nonnull + public DatabasePopulator withPartitionedTableWithoutPrimaryKey() { + statementsToExecuteInSameTransaction.putIfAbsent(111, new CreatePartitionedTableWithoutPrimaryKeyStatement()); + return this; + } + + @Nonnull + public DatabasePopulator withPrimaryKeyForDefaultPartition() { + statementsToExecuteInSameTransaction.putIfAbsent(112, new AddPrimaryKeyForDefaultPartitionStatement()); return this; } diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddPrimaryKeyForDefaultPartitionStatement.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddPrimaryKeyForDefaultPartitionStatement.java new file mode 100644 index 00000000..7de2a51d --- /dev/null +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddPrimaryKeyForDefaultPartitionStatement.java @@ -0,0 +1,26 @@ +/* + * 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.core.fixtures.support.statements; + +import java.util.List; +import javax.annotation.Nonnull; + +public class AddPrimaryKeyForDefaultPartitionStatement extends AbstractDbStatement { + + @Nonnull + @Override + protected List getSqlToExecute() { + return List.of( + "alter table if exists {schemaName}.custom_entity_reference_with_very_very_very_long_name_1_default " + + "add primary key (ref_type, ref_value, creation_date, entity_id);" + ); + } +} diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexWithBooleanValues.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexWithBooleanValuesStatement.java similarity index 90% rename from pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexWithBooleanValues.java rename to pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexWithBooleanValuesStatement.java index 937d3d72..98907cc7 100644 --- a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexWithBooleanValues.java +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexWithBooleanValuesStatement.java @@ -13,7 +13,7 @@ import java.util.List; import javax.annotation.Nonnull; -public class CreateIndexWithBooleanValues extends AbstractDbStatement { +public class CreateIndexWithBooleanValuesStatement extends AbstractDbStatement { @Nonnull @Override diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexWithNullValues.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexWithNullValuesStatement.java similarity index 88% rename from pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexWithNullValues.java rename to pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexWithNullValuesStatement.java index 9a0cbaa6..efba720b 100644 --- a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexWithNullValues.java +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexWithNullValuesStatement.java @@ -13,7 +13,7 @@ import java.util.List; import javax.annotation.Nonnull; -public class CreateIndexWithNullValues extends AbstractDbStatement { +public class CreateIndexWithNullValuesStatement extends AbstractDbStatement { @Nonnull @Override diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexesOnArrayColumn.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexesOnArrayColumnStatement.java similarity index 93% rename from pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexesOnArrayColumn.java rename to pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexesOnArrayColumnStatement.java index 2c27794e..63e9bdca 100644 --- a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexesOnArrayColumn.java +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexesOnArrayColumnStatement.java @@ -13,7 +13,7 @@ import java.util.List; import javax.annotation.Nonnull; -public class CreateIndexesOnArrayColumn extends AbstractDbStatement { +public class CreateIndexesOnArrayColumnStatement extends AbstractDbStatement { @Nonnull @Override diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreatePartitionedTableWithoutComments.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreatePartitionedTableWithoutCommentsStatement.java similarity index 93% rename from pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreatePartitionedTableWithoutComments.java rename to pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreatePartitionedTableWithoutCommentsStatement.java index 44fd2dbe..333e4ce7 100644 --- a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreatePartitionedTableWithoutComments.java +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreatePartitionedTableWithoutCommentsStatement.java @@ -13,7 +13,7 @@ import java.util.List; import javax.annotation.Nonnull; -public class CreatePartitionedTableWithoutComments extends AbstractDbStatement { +public class CreatePartitionedTableWithoutCommentsStatement extends AbstractDbStatement { @Nonnull @Override diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreatePartitionedTableWithoutPrimaryKeyStatement.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreatePartitionedTableWithoutPrimaryKeyStatement.java new file mode 100644 index 00000000..a8602f36 --- /dev/null +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreatePartitionedTableWithoutPrimaryKeyStatement.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.core.fixtures.support.statements; + +import java.util.List; +import javax.annotation.Nonnull; + +public class CreatePartitionedTableWithoutPrimaryKeyStatement extends AbstractDbStatement { + + @Nonnull + @Override + protected List getSqlToExecute() { + return List.of( + "create table if not exists {schemaName}.custom_entity_reference_with_very_very_very_long_name(" + + "ref_type varchar(32) not null," + + "ref_value varchar(64) not null," + + "creation_date timestamp with time zone not null," + + "entity_id varchar(64) not null" + + ") partition by range (creation_date);", + "create table if not exists {schemaName}.custom_entity_reference_with_very_very_very_long_name_1_default " + + "partition of {schemaName}.custom_entity_reference_with_very_very_very_long_name default;" + ); + } +} diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithCheckConstraintOnSerialPrimaryKey.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithCheckConstraintOnSerialPrimaryKeyStatement.java similarity index 88% rename from pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithCheckConstraintOnSerialPrimaryKey.java rename to pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithCheckConstraintOnSerialPrimaryKeyStatement.java index 005572c0..e8f09f91 100644 --- a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithCheckConstraintOnSerialPrimaryKey.java +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithCheckConstraintOnSerialPrimaryKeyStatement.java @@ -13,7 +13,7 @@ import java.util.List; import javax.annotation.Nonnull; -public class CreateTableWithCheckConstraintOnSerialPrimaryKey extends AbstractDbStatement { +public class CreateTableWithCheckConstraintOnSerialPrimaryKeyStatement extends AbstractDbStatement { @Nonnull @Override diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithIdentityPrimaryKey.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithIdentityPrimaryKeyStatement.java similarity index 91% rename from pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithIdentityPrimaryKey.java rename to pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithIdentityPrimaryKeyStatement.java index 17611b1a..addb0577 100644 --- a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithIdentityPrimaryKey.java +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithIdentityPrimaryKeyStatement.java @@ -13,7 +13,7 @@ import java.util.List; import javax.annotation.Nonnull; -public class CreateTableWithIdentityPrimaryKey extends AbstractDbStatement { +public class CreateTableWithIdentityPrimaryKeyStatement extends AbstractDbStatement { @Nonnull @Override diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithSerialPrimaryKeyReferencesToAnotherTable.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithSerialPrimaryKeyReferencesToAnotherTableStatement.java similarity index 95% rename from pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithSerialPrimaryKeyReferencesToAnotherTable.java rename to pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithSerialPrimaryKeyReferencesToAnotherTableStatement.java index ea330209..215b6ccf 100644 --- a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithSerialPrimaryKeyReferencesToAnotherTable.java +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithSerialPrimaryKeyReferencesToAnotherTableStatement.java @@ -13,7 +13,7 @@ import java.util.List; import javax.annotation.Nonnull; -public class CreateTableWithSerialPrimaryKeyReferencesToAnotherTable extends AbstractDbStatement { +public class CreateTableWithSerialPrimaryKeyReferencesToAnotherTableStatement extends AbstractDbStatement { @Nonnull @Override diff --git a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithUniqueSerialColumn.java b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithUniqueSerialColumnStatement.java similarity index 90% rename from pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithUniqueSerialColumn.java rename to pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithUniqueSerialColumnStatement.java index 2226029d..8a69d4c4 100644 --- a/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithUniqueSerialColumn.java +++ b/pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithUniqueSerialColumnStatement.java @@ -13,7 +13,7 @@ import java.util.List; import javax.annotation.Nonnull; -public class CreateTableWithUniqueSerialColumn extends AbstractDbStatement { +public class CreateTableWithUniqueSerialColumnStatement extends AbstractDbStatement { @Nonnull @Override diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesNotLinkedToOthersCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesNotLinkedToOthersCheckOnClusterTest.java index 9fbe0251..2d94eae6 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesNotLinkedToOthersCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesNotLinkedToOthersCheckOnClusterTest.java @@ -48,4 +48,15 @@ void onDatabaseWithThem(final String schemaName) { .isEmpty(); }); } + + @ParameterizedTest + @ValueSource(strings = {PgContext.DEFAULT_SCHEMA_NAME, "custom"}) + void shouldWorkWithPartitionedTables(final String schemaName) { + executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withPartitionedTableWithoutComments(), ctx -> + assertThat(check) + .executing(ctx) + .hasSize(1) + .containsExactly( + Table.of(ctx, "custom_entity_reference_with_very_very_very_long_name"))); + } } diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithoutPrimaryKeyCheckOnClusterTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithoutPrimaryKeyCheckOnClusterTest.java index 157fcb6a..a68081ff 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithoutPrimaryKeyCheckOnClusterTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithoutPrimaryKeyCheckOnClusterTest.java @@ -37,7 +37,7 @@ void shouldSatisfyContract() { @ParameterizedTest @ValueSource(strings = {PgContext.DEFAULT_SCHEMA_NAME, "custom"}) void onDatabaseWithThem(final String schemaName) { - executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withData().withTableWithoutPrimaryKey(), ctx -> { + executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withTableWithoutPrimaryKey(), ctx -> { assertThat(check) .executing(ctx) .hasSize(1) @@ -52,9 +52,33 @@ void onDatabaseWithThem(final String schemaName) { @ParameterizedTest @ValueSource(strings = {PgContext.DEFAULT_SCHEMA_NAME, "custom"}) void shouldReturnNothingForMaterializedViews(final String schemaName) { - executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withData().withMaterializedView(), ctx -> + executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withMaterializedView(), ctx -> assertThat(check) .executing(ctx) .isEmpty()); } + + @ParameterizedTest + @ValueSource(strings = {PgContext.DEFAULT_SCHEMA_NAME, "custom"}) + void shouldWorkWithPartitionedTablesAndPartitions(final String schemaName) { + executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withPartitionedTableWithoutPrimaryKey(), ctx -> + assertThat(check) + .executing(ctx) + .hasSize(2) + .containsExactly( + Table.of(ctx, "custom_entity_reference_with_very_very_very_long_name"), + Table.of(ctx, "custom_entity_reference_with_very_very_very_long_name_1_default") + )); + } + + @ParameterizedTest + @ValueSource(strings = {PgContext.DEFAULT_SCHEMA_NAME, "custom"}) + void shouldWorkWithPartitionedTablesWhenOnlyPartitionsHavePrimaryKeys(final String schemaName) { + executeTestOnDatabase(schemaName, dbp -> dbp.withReferences().withPartitionedTableWithoutPrimaryKey().withPrimaryKeyForDefaultPartition(), ctx -> + assertThat(check) + .executing(ctx) + .hasSize(1) + .containsExactly( + Table.of(ctx, "custom_entity_reference_with_very_very_very_long_name"))); + } }