From 48a139bdcbea12a5d9f445af20a93ce90a78f7c3 Mon Sep 17 00:00:00 2001 From: Martin Wittlinger Date: Mon, 28 Aug 2023 23:32:15 +0200 Subject: [PATCH] =?UTF-8?q?feat(database):=20=E2=9C=A8=20Convert=20liquiba?= =?UTF-8?q?se=20to=20native=20mongodb=20code=20(#994)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- github-bot/build.gradle | 2 -- .../persistence/DataBaseMigration.java | 22 ++++++++++++++++++ .../src/main/resources/application.properties | 4 +--- .../src/main/resources/db/changeLog.xml | 23 ------------------- 4 files changed, 23 insertions(+), 28 deletions(-) delete mode 100644 github-bot/src/main/resources/db/changeLog.xml diff --git a/github-bot/build.gradle b/github-bot/build.gradle index aab5e3c62..5fae7695e 100644 --- a/github-bot/build.gradle +++ b/github-bot/build.gradle @@ -24,8 +24,6 @@ dependencies { implementation("io.quarkus:quarkus-micrometer-registry-prometheus") testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.24.2' implementation("io.quarkus:quarkus-opentelemetry") - implementation("io.quarkus:quarkus-liquibase-mongodb") - implementation("io.quarkus:quarkus-mongodb-client") implementation project(":application") implementation project(":commons") implementation "io.quarkiverse.loggingmanager:quarkus-logging-manager:3.0.1" diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/DataBaseMigration.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/DataBaseMigration.java index 01e973038..bb0bbcd4a 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/DataBaseMigration.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/DataBaseMigration.java @@ -2,6 +2,7 @@ import com.google.common.flogger.FluentLogger; import com.mongodb.client.model.Filters; +import com.mongodb.client.model.IndexOptions; import com.mongodb.client.result.DeleteResult; import io.github.martinwitt.laughing_train.domain.entity.ProjectConfig; import io.github.martinwitt.laughing_train.domain.entity.RemoteProject; @@ -22,6 +23,7 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import org.bson.BsonDocument; /** * This class is used to migrate the database to the latest version. @@ -70,6 +72,7 @@ public void checkPeriodic() { private void migrateDataBase(Promise promise) { logger.atInfo().log("Migrating database"); + createIndexes(); createConfigsIfMissing(); removeProjectHashesWithoutResults(); removeProjectsWithOutHashes(); @@ -81,6 +84,25 @@ private void migrateDataBase(Promise promise) { promise.complete(); } + public void createIndexes() { + try { + badSmellRepositoryImpl + .mongoCollection() + .createIndex(BsonDocument.parse("{commitHash: 1}"), new IndexOptions().name("commitHash_idx")); + badSmellRepositoryImpl + .mongoCollection() + .createIndex(BsonDocument.parse("{ruleID: 1}"), new IndexOptions().name("ruleID_idx")); + badSmellRepositoryImpl + .mongoCollection() + .createIndex( + BsonDocument.parse("{commitHash: 1, ruleID: 1}"), + new IndexOptions().name("commitHash_ruleID_idx")); + } catch (Exception e) { + + logger.atSevere().withCause(e).log("Error while creating indexes"); + } + } + private void removeProjectsWithOutHashes() { logger.atInfo().log("Removing projects without commit hashes"); long value = projectRepository.getAll().stream() diff --git a/github-bot/src/main/resources/application.properties b/github-bot/src/main/resources/application.properties index 4a020c556..4aa0e1e51 100644 --- a/github-bot/src/main/resources/application.properties +++ b/github-bot/src/main/resources/application.properties @@ -54,6 +54,4 @@ quarkus.mongodb.metrics.enabled=true quarkus.http.cors.origins=* %prod.quarkus.oidc.token-state-manager.split-tokens=true quarkus.vertx.max-worker-execute-time=30m -%test.quarkus.scheduler.enabled=false -# Liquibase MongoDB minimal config properties -quarkus.liquibase-mongodb.migrate-at-start=true \ No newline at end of file +%test.quarkus.scheduler.enabled=false \ No newline at end of file diff --git a/github-bot/src/main/resources/db/changeLog.xml b/github-bot/src/main/resources/db/changeLog.xml deleted file mode 100644 index a62e7c496..000000000 --- a/github-bot/src/main/resources/db/changeLog.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - {commitHash: 1} - {name: "commitHash_idx"} - - - {ruleID: 1} - {name: "ruleID_idx"} - - - {commitHash: 1, ruleID:1} - {name: "commitHash_ruleID_idx"} - - - \ No newline at end of file