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

Update mongock to v5 #424

Merged
merged 4 commits into from
Dec 2, 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
2 changes: 1 addition & 1 deletion generators/quarkus/resources/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ commons-vfs2 = { group = "org.apache.commons", name = "commons-vfs2", version =
graal = { group = "org.graalvm.nativeimage", name = "svm", version = "24.1.1" }
mapstruct = { group = "org.mapstruct", name = "mapstruct", version = "1.6.3" }
mapstruct-processor = { group = "org.mapstruct", name = "mapstruct-processor", version = "1.6.3" }
mongock-bom = { group = "com.github.cloudyrock.mongock", name = "mongock-bom", version = "4.3.8" }
mongock-bom = { group = "io.mongock", name = "mongock-bom", version = "5.5.0" }
quarkus-resteasy-problem = { group = "com.tietoevry.quarkus", name = "quarkus-resteasy-problem", version = "3.9.0" }
wiremock = { group = "com.github.tomakehurst", name = "wiremock-jre8", version = "3.0.1" }
testcontainers-keycloak = { group = "com.github.dasniko", name = "testcontainers-keycloak", version = "3.5.1" }
Expand Down
4 changes: 2 additions & 2 deletions generators/quarkus/resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
<frontend-maven-plugin.version>1.15.0</frontend-maven-plugin.version>
<openapi-generator-maven-plugin.version>3.2.3</openapi-generator-maven-plugin.version>
<camel-quarkus-jackson.version>3.11.0</camel-quarkus-jackson.version>
<mongock-bom.version>4.3.8</mongock-bom.version>
<mongock-bom.version>5.5.0</mongock-bom.version>
<commons-vfs2.version>2.9.0</commons-vfs2.version>
<graal.version>23.1.2</graal.version>

<!-- Plugin properties -->
<checkstyle.version>10.17.0</checkstyle.version>
</properties>
</project>
</project>
6 changes: 3 additions & 3 deletions generators/quarkus/templates/build.gradle.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ dependencies {
<%_ } _%>
<%_ if (databaseType === 'mongodb') { _%>
implementation "io.quarkus:quarkus-mongodb-panache"
implementation "com.github.cloudyrock.mongock:mongock-standalone"
implementation "com.github.cloudyrock.mongock:mongodb-sync-v4-driver"
implementation "io.mongock:mongock-standalone"
implementation "io.mongock:mongodb-sync-v4-driver"
implementation "org.apache.commons:commons-lang3"
implementation "org.apache.commons:commons-vfs2:${commons_vfs2_version}"
compileOnly "org.graalvm.nativeimage:svm:${graal_version}"
Expand Down Expand Up @@ -286,7 +286,7 @@ dependencies {
implementation "com.tietoevry.quarkus:quarkus-resteasy-problem:${resteasy_problem_version}"
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
<%_ if (databaseType === 'mongodb') { _%>
implementation enforcedPlatform("com.github.cloudyrock.mongock:mongock-bom:${mongockBom_version}")
implementation enforcedPlatform("io.mongock:mongock-bom:${mongockBom_version}")
<%_ } _%>

annotationProcessor "org.mapstruct:mapstruct-processor:${mapstruct_version}"
Expand Down
4 changes: 2 additions & 2 deletions generators/quarkus/templates/partials/data_pom.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@
<artifactId>quarkus-mongodb-panache</artifactId>
</dependency>
<dependency>
<groupId>com.github.cloudyrock.mongock</groupId>
<groupId>io.mongock</groupId>
<artifactId>mongock-standalone</artifactId>
</dependency>
<dependency>
<groupId>com.github.cloudyrock.mongock</groupId>
<groupId>io.mongock</groupId>
<artifactId>mongodb-sync-v4-driver</artifactId>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion generators/quarkus/templates/pom.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
</dependency>
<%_ if (databaseType === 'mongodb') { _%>
<dependency>
<groupId>com.github.cloudyrock.mongock</groupId>
<groupId>io.mongock</groupId>
<artifactId>mongock-bom</artifactId>
<version>${mongock-bom.version}</version>
<type>pom</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
-%>
package <%=packageName%>.config;

import com.github.cloudyrock.mongock.MongockAnnotationProcessor;
import com.github.cloudyrock.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
import com.github.cloudyrock.standalone.MongockStandalone;
import io.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
import io.mongock.runner.standalone.MongockStandalone;
import io.mongock.api.annotations.ChangeUnit;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
Expand All @@ -43,25 +43,17 @@ public class MongockConfiguration {
@Inject
MongoClient mongoClient;

private static final List<Class<?>> changeLogs;

static {
changeLogs = new MongockAnnotationProcessor().getChangeLogAnnotationClass()
.stream()
.flatMap(changeLogClass ->
new Reflections("<%=packageName%>.config.dbmigrations").getTypesAnnotatedWith(changeLogClass).stream()
)
.collect(Collectors.toList());
}

@ConfigProperty(name = "quarkus.mongodb.database")
String databaseName;

void onStart(@Observes StartupEvent ev) {
var driver = MongoSync4Driver.withDefaultLock(mongoClient, databaseName);
driver.disableTransaction();

MongockStandalone
.builder()
.setDriver(MongoSync4Driver.withDefaultLock(mongoClient, databaseName))
.addChangeLogClasses(changeLogs)
.setDriver(driver)
.addMigrationScanPackage("<%=packageName%>.config.dbmigrations")
.buildRunner()
.execute();
}
Expand All @@ -70,10 +62,11 @@ public class MongockConfiguration {
private static class NativeSupport implements Feature {
@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
changeLogs.forEach(clazz -> {
RuntimeReflection.register(clazz);
RuntimeReflection.register(clazz.getConstructors());
RuntimeReflection.register(clazz.getMethods());
new Reflections("<%=packageName%>.config.dbmigrations")
.getTypesAnnotatedWith(ChangeUnit.class).forEach(clazz -> {
RuntimeReflection.register(clazz);
RuntimeReflection.register(clazz.getConstructors());
RuntimeReflection.register(clazz.getMethods());
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ package <%=packageName%>.config.dbmigrations;
import static org.bson.codecs.configuration.CodecRegistries.fromProviders;
import static org.bson.codecs.configuration.CodecRegistries.fromRegistries;

import com.github.cloudyrock.mongock.ChangeLog;
import com.github.cloudyrock.mongock.ChangeSet;
import io.mongock.api.annotations.ChangeUnit;
import io.mongock.api.annotations.Execution;
import io.mongock.api.annotations.RollbackExecution;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoDatabase;
import <%=packageName%>.security.AuthoritiesConstants;
Expand All @@ -38,11 +39,17 @@ import org.bson.codecs.pojo.PojoCodecProvider;
/**
* Creates the initial database setup.
*/
@ChangeLog(order = "001")
@ChangeUnit(id="users-initialization", order = "001")
public class InitialSetupMigration {

@ChangeSet(order = "01", author = "initiator", id = "01-addAuthorities")
public void addAuthorities(MongoDatabase db) {
private final MongoDatabase db;

public InitialSetupMigration(MongoDatabase db) {
this.db = db;
}

@Execution
public void addAuthorities() {
Authority adminAuthority = new Authority(AuthoritiesConstants.ADMIN);
Authority userAuthority = new Authority(AuthoritiesConstants.USER);

Expand All @@ -51,11 +58,14 @@ public class InitialSetupMigration {
.getCollection("jhi_authority", Authority.class)
.withCodecRegistry(getCodecRegistry())
.insertMany(Arrays.asList(adminAuthority, userAuthority));

<%_ if (authenticationType !== 'oauth2') { _%>
addUsers();
<%_ } _%>
}

<%_ if (authenticationType !== 'oauth2') { _%>
@ChangeSet(order = "02", author = "initiator", id = "02-addUsers")
public void addUsers(MongoDatabase db) {
public void addUsers() {
Authority adminAuthority = new Authority(AuthoritiesConstants.ADMIN);
Authority userAuthority = new Authority(AuthoritiesConstants.USER);

Expand Down Expand Up @@ -113,4 +123,7 @@ public class InitialSetupMigration {
CodecProvider pojoCodecProvider = PojoCodecProvider.builder().automatic(true).build();
return fromRegistries(MongoClientSettings.getDefaultCodecRegistry(), fromProviders(pojoCodecProvider));
}

@RollbackExecution
public void rollback() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import static jakarta.ws.rs.core.Response.Status.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
<%_ if (databaseType === 'mongodb') { _%>
import com.github.cloudyrock.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
import com.github.cloudyrock.standalone.MongockStandalone;
import io.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
import io.mongock.runner.standalone.MongockStandalone;
import com.mongodb.client.MongoClient;
<%_ } _%>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.fail;
<%_ if (databaseType === 'mongodb') { _%>
import com.github.cloudyrock.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
import com.github.cloudyrock.standalone.MongockStandalone;
import io.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
import io.mongock.runner.standalone.MongockStandalone;
import com.mongodb.client.MongoClient;
<%_ } _%>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import io.restassured.common.mapper.TypeRef;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
<%_ if (databaseType === 'mongodb') { _%>
import com.github.cloudyrock.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
import com.github.cloudyrock.standalone.MongockStandalone;
import io.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
import io.mongock.runner.standalone.MongockStandalone;
import com.mongodb.client.MongoClient;
<%_ } _%>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package <%=packageName%>.web.rest;

<%_ if (databaseType === 'mongodb') { _%>
import com.github.cloudyrock.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
import com.github.cloudyrock.standalone.MongockStandalone;
import io.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
import io.mongock.runner.standalone.MongockStandalone;
import com.mongodb.client.MongoClient;
import org.eclipse.microprofile.config.inject.ConfigProperty;
<%_ } _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import static jakarta.ws.rs.core.Response.Status.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.*;
<%_ if (databaseType === 'mongodb') { _%>
import com.github.cloudyrock.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
import com.github.cloudyrock.standalone.MongockStandalone;
import io.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver;
import io.mongock.runner.standalone.MongockStandalone;
import com.mongodb.client.MongoClient;
<%_ } _%>

Expand Down
Loading