Skip to content

Commit

Permalink
feat(database): ✨ Convert liquibase to native mongodb code (#994)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt authored Aug 28, 2023
1 parent 2d0325c commit 48a139b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 28 deletions.
2 changes: 0 additions & 2 deletions github-bot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -70,6 +72,7 @@ public void checkPeriodic() {

private void migrateDataBase(Promise<Object> promise) {
logger.atInfo().log("Migrating database");
createIndexes();
createConfigsIfMissing();
removeProjectHashesWithoutResults();
removeProjectsWithOutHashes();
Expand All @@ -81,6 +84,25 @@ private void migrateDataBase(Promise<Object> 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()
Expand Down
4 changes: 1 addition & 3 deletions github-bot/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
%test.quarkus.scheduler.enabled=false
23 changes: 0 additions & 23 deletions github-bot/src/main/resources/db/changeLog.xml

This file was deleted.

0 comments on commit 48a139b

Please sign in to comment.