Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove tokei badges #379

Merged
merged 2 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
build:
strategy:
matrix:
pg_version: [ "12.17", "13.13", "14.10", "15.5", "16.1" ]
pg_version: [ "12.18", "13.14", "14.11", "15.6", "16.2" ]
env:
TEST_PG_VERSION: ${{ matrix.pg_version }}
runs-on: ubuntu-latest
Expand Down Expand Up @@ -42,16 +42,16 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: Build with Gradle and analyze
if: matrix.pg_version == '14.10'
if: matrix.pg_version == '14.11'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew build sonarqube --info
- name: Build with Gradle
if: matrix.pg_version != '14.10'
if: matrix.pg_version != '14.11'
run: ./gradlew build
- name: Upload coverage to Codecov
if: matrix.pg_version == '14.10'
if: matrix.pg_version == '14.11'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
12 changes: 10 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Java >= 11 is required.

This will build the project and run tests.

By default, [PostgreSQL 16.1 from Testcontainers](https://www.testcontainers.org/) is used to run tests.
By default, [PostgreSQL 16.2 from Testcontainers](https://www.testcontainers.org/) is used to run tests.
Set `TEST_PG_VERSION` environment variable to use any of other available PostgreSQL version:
```
TEST_PG_VERSION=11.20-alpine
Expand All @@ -38,7 +38,7 @@ Domain model is located in a [pg-index-health-model](https://github.com/mfvanek/
All domain classes should be minimalistic and well-defined.
They should include enough information to generate corrective SQL migrations via [pg-index-health-generator](https://github.com/mfvanek/pg-index-health/tree/master/pg-index-health-generator).

### Add the code for a new check
### Add the code for the new check

All checks can be divided into 2 parts:
1. Runtime checks (those that make sense to run only on a production database)
Expand All @@ -63,3 +63,11 @@ Implement a new class extending [AbstractCheckOnCluster](https://github.com/mfva

* Your code must be 100% covered.
* Mutation tests via [pitest](https://pitest.org/) should work.

### Further steps

1. Update readme and add information about the new check
2. Update [Spring Boot starter](https://github.com/mfvanek/pg-index-health-test-starter).
Use a locally built pg-index-health version and send a draft PR.
3. Add sample code to the demo apps ([first](https://github.com/mfvanek/pg-index-health-demo), [second](https://github.com/mfvanek/pg-index-health-spring-boot-demo)).
Use a locally built pg-index-health version and send a draft PR.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,33 @@
[![javadoc](https://javadoc.io/badge2/io.github.mfvanek/pg-index-health/javadoc.svg)](https://javadoc.io/doc/io.github.mfvanek/pg-index-health "javadoc")
[![codecov](https://codecov.io/gh/mfvanek/pg-index-health/branch/master/graph/badge.svg)](https://codecov.io/gh/mfvanek/pg-index-health)

[![Total lines](https://tokei.rs/b1/github/mfvanek/pg-index-health)](https://github.com/mfvanek/pg-index-health)
[![Files](https://tokei.rs/b1/github/mfvanek/pg-index-health?category=files)](https://github.com/mfvanek/pg-index-health)

[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=mfvanek_pg-index-health&metric=bugs)](https://sonarcloud.io/summary/new_code?id=mfvanek_pg-index-health)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=mfvanek_pg-index-health&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=mfvanek_pg-index-health)
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=mfvanek_pg-index-health&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=mfvanek_pg-index-health)
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=mfvanek_pg-index-health&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=mfvanek_pg-index-health)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=mfvanek_pg-index-health&metric=coverage)](https://sonarcloud.io/summary/new_code?id=mfvanek_pg-index-health)

## Supported PostgreSQL versions

[![PostgreSQL 12](https://img.shields.io/badge/PostgreSQL-12-green.svg)](https://www.postgresql.org/about/news/1976/ "PostgreSQL 12")
[![PostgreSQL 13](https://img.shields.io/badge/PostgreSQL-13-green.svg)](https://www.postgresql.org/about/news/postgresql-13-released-2077/ "PostgreSQL 13")
[![PostgreSQL 14](https://img.shields.io/badge/PostgreSQL-14-green.svg)](https://www.postgresql.org/about/news/postgresql-14-released-2318/ "PostgreSQL 14")
[![PostgreSQL 15](https://img.shields.io/badge/PostgreSQL-15-green.svg)](https://www.postgresql.org/about/news/postgresql-15-released-2526/ "PostgreSQL 15")
[![PostgreSQL 16](https://img.shields.io/badge/PostgreSQL-16-green.svg)](https://www.postgresql.org/about/news/postgresql-16-released-2715/ "PostgreSQL 16")

### Support for previous versions of PostgreSQL

Compatibility with PostgreSQL versions **9.6**, **10** and **11** is no longer guaranteed, but it is very likely.
We focus only on the currently maintained versions of PostgreSQL.
For more information please see [PostgreSQL Versioning Policy](https://www.postgresql.org/support/versioning/).

### Supported Java versions

Supports [Java 11](https://www.java.com/en/) and above
For **Java 8** compatible version take a look at release [0.7.0](https://github.com/mfvanek/pg-index-health/releases/tag/v.0.7.0) and lower

## Available checks

**pg-index-health** allows you to detect the following problems:
1. Invalid (broken) indexes ([sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/invalid_indexes.sql)).
2. Duplicated (completely identical) indexes ([sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/duplicated_indexes.sql)).
Expand All @@ -49,16 +50,19 @@ For **Java 8** compatible version take a look at release [0.7.0](https://github.
13. Columns with [json](https://www.postgresql.org/docs/current/datatype-json.html) type ([sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/columns_with_json_type.sql)).
14. Columns of [serial types](https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-SERIAL) that are not primary keys ([sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/non_primary_key_columns_with_serial_types.sql)).
15. Functions without [description](https://www.postgresql.org/docs/current/sql-comment.html) ([sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/functions_without_description.sql)).
16. Indexes [with boolean](https://habr.com/ru/companies/tensor/articles/488104/) ([sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/indexes_with_boolean.sql))

For raw sql queries see [pg-index-health-sql](https://github.com/mfvanek/pg-index-health-sql) project.

## How does it work?

**pg_index_health** utilizes [the Cumulative Statistics System](https://www.postgresql.org/docs/current/monitoring-stats.html)
(formerly known as [PostgreSQL's statistics collector](https://www.postgresql.org/docs/14/monitoring-stats.html)).
You can call `pg_stat_reset()` on each host to reset all statistics counters for the current database to zero
but the best way to do it is to use [DatabaseManagement::resetStatistics()](https://github.com/mfvanek/pg-index-health/blob/1b999374ebc4850ac60e70712399336175348f81/src/main/java/io/github/mfvanek/pg/common/management/DatabaseManagement.java#L32) method.

## Installation

Using Gradle:
```groovy
implementation 'io.github.mfvanek:pg-index-health:0.10.3'
Expand All @@ -82,9 +86,11 @@ Using Maven:
```

## Articles and publications

* [Index health in PostgreSQL through the eyes of a Java developer](https://habr.com/ru/post/490824/)

## How to use

There are three main scenarios of using **pg-index-health** in your projects:
* unit\functional testing;
* collecting indexes health data and monitoring bloat;
Expand All @@ -93,19 +99,14 @@ There are three main scenarios of using **pg-index-health** in your projects:
All these cases are covered with examples in the [pg-index-health-demo](https://github.com/mfvanek/pg-index-health-demo) project.

## Integration with Spring Boot

There is a Spring Boot starter [pg-index-health-test-starter](https://github.com/mfvanek/pg-index-health-test-starter)
for unit/integration testing as well.
More examples you can find in [pg-index-health-spring-boot-demo](https://github.com/mfvanek/pg-index-health-spring-boot-demo) project.

## Questions, issues, feature requests and contributions

* If you have any question or a problem with the library, please [file an issue](https://github.com/mfvanek/pg-index-health/issues).
* Contributions are always welcome! Please see [contributing guide](CONTRIBUTING.md) for more details.
* We utilize [Testcontainers](https://www.testcontainers.org/) for testing **pg-index-health**.
So you need to have [Docker](https://www.docker.com/) installed on your machine.

## Related projects
[pg_analyse](https://github.com/idlesign/pg_analyse) - a set of tools to gather useful information from PostgreSQL,
written in Python, with command line interface.

## Acknowledgements
Supported by [JetBrains](https://www.jetbrains.com/) with [Licenses for Open Source Development](https://www.jetbrains.com/community/opensource/#support)
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.9"

services:
postgres:
image: postgres:16.1
image: postgres:16.2
environment:
POSTGRES_DB: "pgih-db"
POSTGRES_USER: "pgih-db-user"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public boolean isOutParametersInProcedureSupported() {
/**
* Creates {@code PostgreSqlContainerWrapper} with default PostgreSQL version.
* The default version is taken from the environment variable {@code TEST_PG_VERSION} if it is set,
* otherwise the default version {@code 16.1} is used.
* otherwise the default version {@code 16.2} is used.
*
* @return {@code PostgreSqlContainerWrapper}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static String preparePostgresVersion() {
if (pgVersion != null) {
return pgVersion;
}
return "16.1";
return "16.2";
}

@Nonnull
Expand Down Expand Up @@ -114,7 +114,7 @@ static PostgresVersionHolder forCluster(@Nonnull final String pgVersion) {
/**
* Creates {@code PostgresVersionHolder} for single node installation.
* The version is taken from the environment variable {@code TEST_PG_VERSION} if it is set,
* otherwise the default version {@code 16.1} is used.
* otherwise the default version {@code 16.2} is used.
*
* @return {@code PostgresVersionHolder}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void withDefaultVersionShouldWork() {

@Test
void withVersionShouldWork() {
try (PostgreSqlContainerWrapper container = PostgreSqlContainerWrapper.withVersion("16.1")) {
try (PostgreSqlContainerWrapper container = PostgreSqlContainerWrapper.withVersion("16.2")) {
assertThat(container)
.isNotNull()
.satisfies(c -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void forClusterShouldBeBitnamiAware() {
.isEqualTo(System.getenv("TEST_PG_VERSION").split("-")[0] + ".0");
} else {
assertThat(versionHolder.getVersion())
.isEqualTo("16.1.0");
.isEqualTo("16.2.0");
}
}

Expand Down Expand Up @@ -110,7 +110,7 @@ void forSingleNodeShouldBeEnvAware() {
.isEqualTo(System.getenv("TEST_PG_VERSION"));
} else {
assertThat(versionHolder.getVersion())
.isEqualTo("16.1");
.isEqualTo("16.2");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class PostgresVersionTest extends DatabaseAwareTestBase {
@Test
void checkPgVersion() {
final String pgVersionFromEnv = System.getenv(PG_VERSION_ENVIRONMENT_VARIABLE);
final String requiredPgVersionString = (pgVersionFromEnv == null) ? "16.1 (Debian 16.1-" : pgVersionFromEnv.split("-")[0];
final String requiredPgVersionString = (pgVersionFromEnv == null) ? "16.2 (Debian 16.2-" : pgVersionFromEnv.split("-")[0];
final String actualPgVersionString = PostgresVersionReader.readVersion(getDataSource());
assertThat(actualPgVersionString)
.startsWith(requiredPgVersionString);
Expand Down