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

feat(database): ✨ Convert liquibase to native mongodb code #994

Merged
merged 1 commit into from
Aug 28, 2023
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
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.