-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check "The type of the foreign key must match the type of column …
…in the target table" (#471) * Update queries * Add new check * Javadoc * Add tests * Add logger and tests * Refactor Spring configuration * Refactor Spring configuration * Refactor Spring configuration #3 * Fix tests * Update PMD #2
- Loading branch information
Showing
52 changed files
with
596 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
.../java/io/github/mfvanek/pg/checks/host/ForeignKeysWithUnmatchedColumnTypeCheckOnHost.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.checks.host; | ||
|
||
import io.github.mfvanek.pg.checks.extractors.ForeignKeyExtractor; | ||
import io.github.mfvanek.pg.common.maintenance.Diagnostic; | ||
import io.github.mfvanek.pg.connection.PgConnection; | ||
import io.github.mfvanek.pg.model.PgContext; | ||
import io.github.mfvanek.pg.model.constraint.ForeignKey; | ||
|
||
import java.util.List; | ||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Check for foreign keys where the type of the constrained column does not match the type in the referenced table on a specific host. | ||
* <p> | ||
* The column types in the referring and target relation must match. | ||
* For example, a column with the {@code integer} type should refer to a column with the {@code integer} type. | ||
* This eliminates unnecessary conversions at the DBMS level and in the application code, | ||
* and reduces the number of errors that may appear due to type inconsistencies in the future. | ||
* | ||
* @author Ivan Vahrushev | ||
* @see <a href="https://www.postgresql.org/docs/current/catalog-pg-constraint.html">pg_constraint</a> | ||
* @since 0.13.2 | ||
*/ | ||
public class ForeignKeysWithUnmatchedColumnTypeCheckOnHost extends AbstractCheckOnHost<ForeignKey> { | ||
|
||
public ForeignKeysWithUnmatchedColumnTypeCheckOnHost(@Nonnull final PgConnection pgConnection) { | ||
super(ForeignKey.class, pgConnection, Diagnostic.FOREIGN_KEYS_WITH_UNMATCHED_COLUMN_TYPE); | ||
} | ||
|
||
/** | ||
* Returns foreign keys where the type of the constrained column does not match the type in the referenced table. | ||
* <p> | ||
* For multi-column constraints returns only columns with differences. | ||
* | ||
* @param pgContext check's context with the specified schema; must not be null | ||
* @return list of foreign keys where the type of the constrained column does not match the type in the referenced table | ||
*/ | ||
@Nonnull | ||
@Override | ||
protected List<ForeignKey> doCheck(@Nonnull final PgContext pgContext) { | ||
return executeQuery(pgContext, ForeignKeyExtractor.ofDefault()); | ||
} | ||
} |
Oops, something went wrong.