Skip to content

Commit

Permalink
Merge pull request #29 from mfvanek/featrue/migrating-to-v0.6.2
Browse files Browse the repository at this point in the history
Upgraded pg-index-health version up to 0.6.2
  • Loading branch information
mfvanek authored Sep 18, 2022
2 parents 5a05f21 + aa5c554 commit 22ef28f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
38 changes: 18 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ plugins {
id 'jacoco'
id 'pmd'
id 'org.sonarqube' version '3.3'
id 'io.freefair.lombok' version '6.5.0.3'
id 'io.freefair.lombok' version '6.5.1'
id 'info.solidsoft.pitest' version '1.9.0'
}

group 'io.github.mfvanek'
version '0.6.2-SNAPSHOT'
version '0.6.3-SNAPSHOT'

java {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -22,26 +22,24 @@ repositories {
mavenCentral()
}

def junitVersion = '5.9.0'
def testContainersVersion = '1.17.3'
dependencies {
implementation 'ch.qos.logback:logback-classic:1.2.11'
implementation 'io.github.mfvanek:pg-index-health:0.6.1'
implementation 'org.postgresql:postgresql:42.4.2'
implementation 'ch.qos.logback:logback-classic:1.3.1'
implementation 'io.github.mfvanek:pg-index-health:0.6.2'
implementation 'org.postgresql:postgresql:42.5.0'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'org.liquibase:liquibase-core:4.15.0'
implementation 'org.yaml:snakeyaml:1.30'
implementation 'javax.activation:activation:1.1.1'
implementation 'org.liquibase:liquibase-core:4.16.1'
implementation 'org.apache.commons:commons-dbcp2:2.9.0'
implementation "org.testcontainers:testcontainers:$testContainersVersion"
implementation "org.testcontainers:postgresql:$testContainersVersion"
implementation enforcedPlatform('org.testcontainers:testcontainers-bom:1.17.3')
implementation 'org.testcontainers:testcontainers'
implementation 'org.testcontainers:postgresql'

testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
testImplementation enforcedPlatform('org.junit:junit-bom:5.9.0')
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testImplementation 'org.assertj:assertj-core:3.23.1'
testImplementation "org.testcontainers:junit-jupiter:$testContainersVersion"
testImplementation 'org.mockito:mockito-core:4.7.0'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.mockito:mockito-core:4.8.0'

pitest 'it.mulders.stryker:pit-dashboard-reporter:0.1.2'
}
Expand Down Expand Up @@ -72,7 +70,7 @@ spotbugs {
}

checkstyle {
toolVersion '10.3.1'
toolVersion '10.3.3'
configFile file("config/checkstyle/checkstyle.xml")
ignoreFailures = false
maxWarnings = 0
Expand Down Expand Up @@ -129,7 +127,7 @@ check.dependsOn jacocoTestReport, jacocoTestCoverageVerification

pmd {
consoleOutput = true
toolVersion = "6.47.0"
toolVersion = "6.49.0"
ruleSetFiles = files("config/pmd/pmd.xml")
ruleSets = []
}
Expand All @@ -144,7 +142,7 @@ sonarqube {

pitest {
junit5PluginVersion = '1.0.0'
pitestVersion = '1.9.4'
pitestVersion = '1.9.5'
threads = 4
outputFormats = System.getenv('STRYKER_DASHBOARD_API_KEY') != null ? ['stryker-dashboard'] : ['HTML']
timestampedReports = false
Expand Down
1 change: 1 addition & 0 deletions config/pmd/pmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<exclude name="LoosePackageCoupling"/>
<exclude name="AvoidCatchingGenericException"/>
<exclude name="UseUtilityClass"/>
<exclude name="ExcessiveImports"/>
</rule>

<rule ref="category/java/design.xml/AbstractClassWithoutAnyMethod">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
package io.github.mfvanek.pg.index.health.demo.utils;

import io.github.mfvanek.pg.checks.cluster.ForeignKeysNotCoveredWithIndexCheckOnCluster;
import io.github.mfvanek.pg.common.maintenance.AbstractCheckOnCluster;
import io.github.mfvanek.pg.common.maintenance.DatabaseCheckOnCluster;
import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection;
import io.github.mfvanek.pg.connection.HighAvailabilityPgConnectionImpl;
import io.github.mfvanek.pg.connection.PgConnectionImpl;
import io.github.mfvanek.pg.generator.DbMigrationGenerator;
import io.github.mfvanek.pg.generator.DbMigrationGeneratorImpl;
import io.github.mfvanek.pg.generator.ForeignKeyMigrationGenerator;
import io.github.mfvanek.pg.generator.GeneratingOptions;
import io.github.mfvanek.pg.model.PgContext;
import io.github.mfvanek.pg.model.index.ForeignKey;
Expand All @@ -33,14 +33,14 @@ public class MigrationsGenerator {

public static List<ForeignKey> getForeignKeysNotCoveredWithIndex(@Nonnull final DataSource dataSource) {
final HighAvailabilityPgConnection haPgConnection = HighAvailabilityPgConnectionImpl.of(PgConnectionImpl.ofPrimary(dataSource));
final AbstractCheckOnCluster<ForeignKey> foreignKeysNotCoveredWithIndex = new ForeignKeysNotCoveredWithIndexCheckOnCluster(haPgConnection);
final DatabaseCheckOnCluster<ForeignKey> foreignKeysNotCoveredWithIndex = new ForeignKeysNotCoveredWithIndexCheckOnCluster(haPgConnection);
return foreignKeysNotCoveredWithIndex.check(PgContext.of("demo"));
}

@SneakyThrows
public static void generateMigrations(@Nonnull final DataSource dataSource, @Nonnull final List<ForeignKey> foreignKeys) {
final DbMigrationGenerator generator = new DbMigrationGeneratorImpl();
final String generatedMigrations = generator.generate(foreignKeys, GeneratingOptions.builder().build());
final DbMigrationGenerator<ForeignKey> generator = new ForeignKeyMigrationGenerator(GeneratingOptions.builder().build());
final String generatedMigrations = generator.generate(foreignKeys);
log.info(generatedMigrations);
try (Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ void shouldWork() {
assertThatCode(() -> DemoApp.main(new String[]{}))
.doesNotThrowAnyException();
assertThat(getLogs())
.hasSize(14)
.hasSize(15)
.filteredOn(l -> l.getLoggerName().contains("MigrationRunner"))
.hasSize(1)
.allMatch(l -> l.getMessage().startsWith("Migrations have been successfully executed"));
assertThat(getLogs())
.filteredOn(l -> l.getLoggerName().contains("HealthDataCollector"))
.hasSize(13);
.hasSize(14);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package io.github.mfvanek.pg.index.health.demo;

import io.github.mfvanek.pg.checks.host.ColumnsWithJsonTypeCheckOnHost;
import io.github.mfvanek.pg.checks.host.ColumnsWithSerialTypesCheckOnHost;
import io.github.mfvanek.pg.checks.host.ColumnsWithoutDescriptionCheckOnHost;
import io.github.mfvanek.pg.checks.host.DuplicatedIndexesCheckOnHost;
import io.github.mfvanek.pg.checks.host.ForeignKeysNotCoveredWithIndexCheckOnHost;
Expand Down Expand Up @@ -55,6 +56,7 @@ class IndexesMaintenanceTest extends DatabaseAwareTestBase {
private final TablesWithoutDescriptionCheckOnHost tablesWithoutDescriptionCheck;
private final ColumnsWithoutDescriptionCheckOnHost columnsWithoutDescriptionCheck;
private final ColumnsWithJsonTypeCheckOnHost columnsWithJsonTypeCheckOnHost;
private final ColumnsWithSerialTypesCheckOnHost columnsWithSerialTypesCheckOnHost;

IndexesMaintenanceTest() {
final PgConnection pgConnection = PgConnectionImpl.ofPrimary(getDataSource());
Expand All @@ -67,6 +69,7 @@ class IndexesMaintenanceTest extends DatabaseAwareTestBase {
this.tablesWithoutDescriptionCheck = new TablesWithoutDescriptionCheckOnHost(pgConnection);
this.columnsWithoutDescriptionCheck = new ColumnsWithoutDescriptionCheckOnHost(pgConnection);
this.columnsWithJsonTypeCheckOnHost = new ColumnsWithJsonTypeCheckOnHost(pgConnection);
this.columnsWithSerialTypesCheckOnHost = new ColumnsWithSerialTypesCheckOnHost(pgConnection);
}

@Test
Expand Down Expand Up @@ -215,4 +218,11 @@ void getColumnsWithJsonTypeShouldReturnNothingForAllSchemas(@Nonnull final Strin
assertThat(columnsWithJsonTypeCheckOnHost.check(PgContext.of(schemaName)))
.isEmpty();
}

@ParameterizedTest
@ValueSource(strings = {"public", "demo"})
void getColumnsWithSerialTypesShouldReturnNothingForAllSchemas(@Nonnull final String schemaName) {
assertThat(columnsWithSerialTypesCheckOnHost.check(PgContext.of(schemaName)))
.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ void shouldCollectHealthData() {
"db_indexes_health\ttables_with_bloat\t0",
"db_indexes_health\ttables_without_description\t0",
"db_indexes_health\tcolumns_without_description\t0",
"db_indexes_health\tcolumns_with_json_type\t0");
"db_indexes_health\tcolumns_with_json_type\t0",
"db_indexes_health\tcolumns_with_serial_types\t0");
final List<String> healthData = HealthDataCollector.collectHealthData(getConnectionCredentials());
assertThat(healthData)
.hasSize(13)
.hasSize(14)
.matches(l -> l.stream().allMatch(s -> expected.stream().anyMatch(s::contains)));
}
}

0 comments on commit 22ef28f

Please sign in to comment.