Coder Social home page Coder Social logo

mongock / mongock Goto Github PK

View Code? Open in Web Editor NEW
429.0 429.0 62.0 3.57 MB

Lightweight Java based migration tool

License: Apache License 2.0

Java 94.69% Shell 0.03% Kotlin 5.28%
database java migration mongock mongodb nosql spring spring-boot sql

mongock's Introduction

Lightweight Java based migration tool


Maven Central Codacy Badge Build Hex.pm Bugs Vulnerabilities

Mongock is a Java based migration tool as part of your application code. It allows developers to have ownership and control over data migrations during the deployment process, allowing safer migrations in distributed systems as code and data changes are shipped together.

Documentation

The official documentation is here, where you can find everything rom version 3.

Professional support ๐Ÿš€

Mongock professional is the extension of the Mongock open source project. This provides some additional advantages such as:

  • Advanced features exclusive to the Professional version.
  • New community features are available and released to the professional version as well.
  • Professional support for the tool usage is backed by Mongock Ltd, providing your business with additional help and responses.

Visit this link to get started.

Examples

Mongock examples

Stay tuned

To be updated with the latest releases, notifications and news, follow us on twitter ๐Ÿ˜‰

Questions

Before rasing a question, please check it hasn't been alerady answered in

  1. Our FAQ section
  2. Github Q&A section
  3. Stackoverflow
  4. Gitter channel

If you cannot find the answer you are looking for, feel free to raise a new question in our Gitter channel or Q&A section

Issues

To raise a new issue, please take a look to this guide

Changelog

To see our changelog, please take a look to our github releases

Older versions support

With new major releases we stop enhancing or adding new features to older version(like version 3 or 4). However, we'll keep providing support and bug fixes for a long period. We are working on an official support plan.

Code of conduct

Please read the code of conduct for details on our code of conduct.

LICENSE

Mongock project is licensed under the Apache License Version 2.0. See the LICENSE file for details

Contributing

๐ŸŽ‰ First off, thanks for taking the time to contribute! ๐ŸŽ‰

If you would like to contribute to the Mongock project, visit our official documentation

mongock's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mongock's Issues

Mongock.execute needs to be public

In the "Usage without Spring" section, the README shows manually calling runner.execute();. However, the execute method is package-protected. This needs to be public to work as documented. As a workaround, it looks like I can manually call afterPropertiesSet().

Add ability to use own ChangeLog implementations

Description

Injecting own ChangeLogs into builder to control properties of the object.

Something like:

@ChangeLog
@AllArgsConstructor
@NoArgsConstructor
public class DatabaseChangeLog {
        
        private EnvConfig config;     // application properties

        @ChangeSet(order = "001", id = "createInitialDatabase", author = "Matt")
        public void initial() {
           ...
        }

Specific scenario

Unable to specify specific safety provisions for my prod environment.

PRIORITY

minor

Potential issues or difficulties

Consumers of this library will need to be aware that the method level database accessors provide the locking mechanism and so need to be careful not to inject their own persistence implementations.

Expected behavior

Fields in ChangeLogs won't necessarily be null anymore.

PRIORITY

MINOR

default name of change log collection missleading in README.md

In the README.md's Standalone section (https://github.com/cloudyrock/mongock/blob/master/README.md#standalone-usage) the default for the change log collection is given as "dbchangelog".

builder.setChangelogCollectionName(logColName); // default is dbchangelog, collection with applied change sets

This seams to be incorrect for version 2.0.2 here the collection is called "mongockChangeLog" by default. (I did not check the source code for other versions.)

This documentation misled me when I was setting up Mongock last week.

Display time duration for every changeset

Thanks you for the wonderful product! Is it possible to add one more column for mongockChangeLog collection and keep records of execution time for every changeset?

Can't use Mongock without Spring

It is not possible to use Mongock without Spring given the current declaration of the class:

public class Mongock implements InitializingBean, Closeable {
// ...
}

I think the fix here should be pretty easy...just create a separate subclass that adds in the Spring capabilities:

public class Mongock implements Closeable {
// ...
}

public class SpringMongock extends Mongock implements InitializingBean {
// ...
}

Mongock reexecutes ChangeSet on every run

In version 3.0.8 Mongock does not respect changelog reexecuting already executed change sets on every run (despite "runAlways" is false). In 2.0.2 everything is OK.
BTW I don't use "version" field, only "id".

ChangeSet.runAlways not working for mongock version 3.2.3

  • Spring-Boot version - 2.2.3.RELEASE
  • Spring management plugin version - 1.0.9.RELEASE
  • Mongo db version - 4.2.3

My Configuration -

@Changeset(id = "alwaysRunMigrations", order = "011", author = "my_service", systemVersion = "4", runAlways = true)

Error -
Caused by: com.mongodb.MongoWriteException: E11000 duplicate key error collection: myDB.mongockChangeLog index: author_1_changeId_1 dup key: { author: "my_service", changeId: "alwaysRunMigrations" } at com.mongodb.client.internal.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:1055) ~[mongodb-driver-3.11.2.jar:?] at com.mongodb.client.internal.MongoCollectionImpl.executeInsertOne(MongoCollectionImpl.java:498) ~[mongodb-driver-3.11.2.jar:?] at com.mongodb.client.internal.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:482) ~[mongodb-driver-3.11.2.jar:?] at com.mongodb.client.internal.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:476) ~[mongodb-driver-3.11.2.jar:?] at com.github.cloudyrock.mongock.ChangeEntryMongoRepository.save(ChangeEntryMongoRepository.java:26) ~[mongock-core-3.2.3.jar:?] at com.github.cloudyrock.mongock.Mongock.executeIfNewOrRunAlways(Mongock.java:153) ~[mongock-core-3.2.3.jar:?]

Entities with @Indexed cause Mongock instantiation failure

Hello

We are trying out mongock in a Spring Boot project. The creation of the SpringBootMongock bean seems to fail when an entity with the @Indexed annotation exists. When removing the @Indexed annotation from the (unrelated) entity, everything works as expected. Note that the indices have been correctly created by the time the SpringBootMongock bean instantiation fails.

full annotation name: org.springframework.data.mongodb.core.index.Indexed

Our setup:

@Configuration
public class MongockConfig {

    private static final String CHANGE_LOGS_SCAN_PACKAGE = "my.company.servicename.persistence.upgrade";

    private final MongoTemplate mongoTemplate;
    private final ApplicationContext applicationContext;

    @Autowired
    public MongockConfig(MongoTemplate mongoTemplate, ApplicationContext applicationContext) {
        this.mongoTemplate = mongoTemplate;
        this.applicationContext = applicationContext;
    }

    @Bean
    public Mongock mongock() {
        return new SpringBootMongockBuilder(mongoTemplate, CHANGE_LOGS_SCAN_PACKAGE)
                .setApplicationContext(applicationContext)
                .setLockQuickConfig()
                .build();
    }
}
@ChangeLog
public class MongoChangeLog {

    private static final String CHANGE_SET_001 = "change-set-001.yaml";

    @ChangeSet(order = "001", id = "cefc0a3d-1905-46d2-8635-e7a468c40fec", author = "author")
    public void changeSet001(AircraftDao aircraftDao) {
        UpgradeUtils.createAircraftEntities(getClass().getResourceAsStream(CHANGE_SET_001))
                .forEach(aircraftDao::save);
    }
}

Entity causing issues

@Data
@Builder
@Document
public class Attachment {

    @Id
    private String id;
    @Indexed(name="expire-index", expireAfter="P2D")
    private LocalDateTime createdAt;
    ...
}
11:37:46.578 - ERROR - org.springframework.boot.SpringApplication - Application run failed
 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongock' defined in class path resource [my/company/service/persistence/config/MongockConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.mongock.Mongock]: Factory method 'mongock' threw exception; nested exception is java.lang.NullPointerException
 	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:656)
 	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:484)
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
 	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
 	at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$240.000000008C98DDC0.getObject(Unknown Source)
 	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
 	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
 	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
 	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
 	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
 	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
 	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
 	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
 	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
 	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
 	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
 	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
 	at my.company.servicename.application.GeodataServiceApplication.main(GeodataServiceApplication.java:13)
 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
 	at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
 	at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
 	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
 Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.mongock.Mongock]: Factory method 'mongock' threw exception; nested exception is java.lang.NullPointerException
 	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
 	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651)
 	... 28 common frames omitted
 Caused by: java.lang.NullPointerException: null
 	at com.github.cloudyrock.mongock.decorator.impl.MongoTemplateDecoratorImpl.execute(MongoTemplateDecoratorImpl.java:154)
 	at org.springframework.data.mongodb.core.DefaultIndexOperations.execute(DefaultIndexOperations.java:214)
 	at org.springframework.data.mongodb.core.DefaultIndexOperations.ensureIndex(DefaultIndexOperations.java:121)
 	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.createIndex(MongoPersistentEntityIndexCreator.java:158)
 	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.checkForAndCreateIndexes(MongoPersistentEntityIndexCreator.java:148)
 	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.checkForIndexes(MongoPersistentEntityIndexCreator.java:130)
 	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.<init>(MongoPersistentEntityIndexCreator.java:95)
 	at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator.<init>(MongoPersistentEntityIndexCreator.java:72)
 	at org.springframework.data.mongodb.core.MongoTemplate.<init>(MongoTemplate.java:275)
 	at com.github.cloudyrock.mongock.decorator.impl.MongoTemplateDecoratorImpl.<init>(MongoTemplateDecoratorImpl.java:65)
 	at com.github.cloudyrock.mongock.SpringMongockBuilderBase.createMongoTemplateProxy(SpringMongockBuilderBase.java:115)
 	at com.github.cloudyrock.mongock.SpringBootMongockBuilder.createMongockInstance(SpringBootMongockBuilder.java:71)
 	at com.github.cloudyrock.mongock.SpringBootMongockBuilder.createMongockInstance(SpringBootMongockBuilder.java:11)
 	at com.github.cloudyrock.mongock.MongockBuilderBase.build(MongockBuilderBase.java:197)
 	at my.company.servicename.persistence.config.MongockConfig.mongock(MongockConfig.java:30)
 	at my.company.servicename.persistence.config.MongockConfig$$EnhancerBySpringCGLIB$$e83328b9.CGLIB$mongock$0(<generated>)
 	at my.company.servicename.persistence.config.MongockConfig$$EnhancerBySpringCGLIB$$e83328b9$$FastClassBySpringCGLIB$$a6a217f8.invoke(<generated>)
 	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
 	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)
 	at my.company.servicename.persistence.config.MongockConfig$$EnhancerBySpringCGLIB$$e83328b9.mongock(<generated>)
 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
 	... 29 common frames omitted

Builder's children classes return parent class in methods where it should return the actual class

Description

When executing methods like setLockQuickConfig() the children classes return and instance of the parent class(notice it's actual the child instance, but the method's signature returns the parent class)

PRIORITY

Normal

Steps to reproduce

Use for example SpringBootMongockBuilder and invoke method setLockQuickConfig(), it will return a instance of MongockBuilder

Specific scenario

The same as above

Behaviour

Expected behaviour: For the example in steps to reproduce, it should return an instance of SpringBootMongockBuilder

Actual behaviour: It returns an instance of MongockBuilder
Reproduces how often: always

Version

2.0.0 and previous

MongoTemplate argument in changeset's method doesn't work (Dropwizard)

I use Dropwizard and Spring Data in our project and Mongock. Migration tool works fine when changeset methods contains com.mongodb.client.MongoDatabase, but when I have tried it use with Spring's MongoTemplate argument as your documentations propose:

@ChangeSet(order = "005", id = "someChangeWithSpringDataTemplate", author = "testAuthor") public void someChange5(MongoTemplate mongoTemplate) { // type: org.springframework.data.mongodb.core.MongoTemplate // Spring Data integration allows using MongoTemplate in the ChangeSet // example: mongoTemplate.save(myEntity); }

I ended in ERROR with error message: ChangeSet method has wrong arguments list. Please see docs for more info!

Then I have search in your code for this occurrence in your code and I found method called Mongock.executeChangeSetMethod where according to your code you do not support anything else then the MongoDatabase. So there are only two explanation for me:

  • You have obsolete documentation and do not support Spring Data.
  • Is it not possible to run it with Dropwizard with Spring Data dependencies.

I also have learnt that in another dev team which use MongoBeeJ, Dropwizard and Spring Data they managed to run it with MongoTemplate argument in ChangeSet methods. I would rather not migrate to another library because of this. I would be more than happy to hear any helpful information from your side.

Dependencies:

  • io.dropwizard:dropwizard-core:jar:1.3.12
  • org.mongodb:mongo-java-driver:jar:3.11.0
  • org.springframework.data:spring-data-mongodb:jar:1.10.18.RELEASE
  • com.github.cloudyrock.mongock:mongock-core:2.0.2
  • com.github.cloudyrock.mongock:mongock-spring:jar:2.0.2

Allow own changelog instances instead of newInstance

Currently unable to control the creation of the ChangeLog objects. It would be nice to use custom ones I can pass to the builder so I can add fields based on application configuration, or even use other mongo driver wrappers like Morphia (without relying on set method parameters)

I've tried on core and it seems not doable unless I'm missing something, I imagine this is easier with the spring version.

Spring Boot 2.1.5

Description
I am currently migrating my team's code to Spring Boot 2.1.5. We were previously using MongoBee but are now changing to Mongock (if I can get it to work).

I am getting the below error when running using maven and Intellij...

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
14:56:29.910 [main] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongock-spring-boot' defined in class path resource [com/agilysys/platform/authservice/migration/MigrationConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.mongock.SpringBootMongock]: Factory method 'mongock' threw exception; nested exception is java.lang.ExceptionInInitializerError
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:843)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
	at com.agilysys.platform.authservice.Application.main(Application.java:121)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.mongock.SpringBootMongock]: Factory method 'mongock' threw exception; nested exception is java.lang.ExceptionInInitializerError
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
	... 19 common frames omitted
Caused by: java.lang.ExceptionInInitializerError: null
	at com.github.cloudyrock.mongock.ProxyFactory.createProxyClass(ProxyFactory.java:59)
	at com.github.cloudyrock.mongock.ProxyFactory.createProxyFromOriginal(ProxyFactory.java:105)
	at com.github.cloudyrock.mongock.SpringBootMongockBuilder.createMongoDataBaseProxy(SpringBootMongockBuilder.java:72)
	at com.github.cloudyrock.mongock.SpringBootMongockBuilder.createBuild(SpringBootMongockBuilder.java:48)
	at com.github.cloudyrock.mongock.SpringBootMongockBuilder.createBuild(SpringBootMongockBuilder.java:16)
	at com.github.cloudyrock.mongock.MongockBuilderBase.build(MongockBuilderBase.java:148)
	at com.agilysys.platform.authservice.migration.MigrationConfiguration.mongock(MigrationConfiguration.java:34)
	at com.agilysys.platform.authservice.migration.MigrationConfiguration$$EnhancerBySpringCGLIB$$68f5577a.CGLIB$mongock$0(<generated>)
	at com.agilysys.platform.authservice.migration.MigrationConfiguration$$EnhancerBySpringCGLIB$$68f5577a$$FastClassBySpringCGLIB$$dc493876.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)
	at com.agilysys.platform.authservice.migration.MigrationConfiguration$$EnhancerBySpringCGLIB$$68f5577a.mongock(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 20 common frames omitted
Caused by: java.lang.IllegalArgumentException: null
	at org.objectweb.asm.ClassVisitor.<init>(Unknown Source)
	at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:49)
	at net.sf.cglib.core.DefaultGeneratorStrategy.getClassVisitor(DefaultGeneratorStrategy.java:30)
	at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
	at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:329)
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93)
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91)
	at net.sf.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at net.sf.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
	at net.sf.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116)
	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291)
	at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221)
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:174)
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:153)
	at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:73)
	... 37 common frames omitted

Process finished with exit code 1

And my @configuration class looks like...

@Configuration
public class MigrationConfiguration {

    private static final String lockName = "AuthMongockLock";
    private static final String packageName = "com.agilysys.platform.authservice.migration";

    @Value("${mongodb-dbname:${mongo.db.dbname:}}")
    private String dbName;

    @Bean("mongock-spring-boot")
    public SpringBootMongock mongock(ApplicationContext springContext, MongoClient mongoClient) {
        return new SpringBootMongockBuilder(mongoClient, dbName, packageName)
                .setApplicationContext(springContext)
                .setLockQuickConfig()
                .build();
    }
}

PRIORITY
Normal

Steps to Reproduce
Create a Spring Boot 2.1.5 project and try to use Mongock-Spring 2.0.2.

Specific scenario
I have looked at the sample projects provided for Spring-Mongock and they don't seem to solve any of my issues. I have even tried switching to use the stand alone library but that didn't help.

Behaviour
Expected behavior: Application should start and run my existing migration methods.

Actual behavior: Application fails to start.

Reproduces how often: 100%

Version
2.0.2

Link to repository using Mongock
Not possible.

Additional Information
Thanks

Versioning for ChangeLogs

Is there any possibility to tag my change-logs with a version?

I would like to keep my change-logs for multiple DB upgrades and just execute the ones which are needed to upgrade from my current to the latest version.

This will be unnecessary complicated with just using the "changeLogsScanPackage" as grouping of the change-logs:

  1. group all change-logs per version in separate packages
  2. create multiple MongockBuilder
  3. execute all of them which are between the current and the target version

Beside of that by using the history of applied change sets (stored in a collection called dbchangelog)
I need to pre fill the collection with the outdated change-sets to avoid running them.

Usage with SpringBoot - ApplicationRunner

As of now the library uses ApplicationRunner, thus the migrations will run after the app has started.

I would like to have the application start fail if my migrations fail.

I did not find a way to configure this.

Would it be a welcome addition to the codebase to add this feature if it's not yet configurable?

Injections in SpringBoot monitored by the lock

Description

The ability to inject spring dependencies via context was added as enhancement(Spring boot), but there MongoTemplate, MongoDatabase and DB are not being proxied, so the lock mechanism is not guaranteed .

PRIORITY

CRITICAL

Specific scenario

Using spring boot

Behaviour

Expected behaviour:
Injected MongoTemplate, MongoDatabase and DB being proxied(monitored)

Actual behavior:
Injected MongoTemplate, MongoDatabase and DB are not proxied(monitored)

Reproduces how often:
100%

Version

All versions of Spring boot up to 2.0.1

Link to repository using Mongock

[While no mandatory, accessing to the real code that uses Mongock, would help to solve the issue]

Additional Information

Springboot shouldn't be used until fix

Survey for Mongock roadmap

Hi all, we are designing the roadmap for the next features and we think that it's crucial that we understand the user's needs and preferences. For this we have created a quick survey to understand what is important for you and also to allow you to give us any idea or need you have and we haven't thought about.

We would really appreciate you take 2 minutes to fill it.
Thanks in Advance.

Mongock roadmap survey

Track all the changeSet with its execution result/state, regardless if it was executed

The idea is to provide all the required and useful information in the changeLog entry in the database, so it can be later analysed and it can be easily understood.

So the changeSet will be always tracked in the database, but it will the execution result, like SUCCESS, RE-APPLIED, PASSED-OVER, FAILED

This will require updating the Mongock collection structure, so it will need to apply Mongock for Mongock collections :D
This may require issue #125

Exception when using MongoDatabase

Description
When using MongoDatabse, Mongock throws an exception due to MongoDatabseImpl is package private

PRIORITY
Critical as MongoDatabase is the standard way of using the Mongock-core

Steps to Reproduce

  • Use Mongock-core
  • Don't us DB. Mongock will take MongoDatabase by default
  • Code:

`

MongoClient mongoclient = new MongoClient(new MongoClientURI("mongodb://127.0.0.1:27017"));
Mongock mongock = new MongockBuilder(mongoclient,
"mongock_demo2",
"com.github.cloudyrock.mongock.springboot1518sample.changesets")
.setLockQuickConfig()
.build();
mongock.execute();

`

Specific scenario
Mongock-core when not using DB

Behaviour

  • Expected behaviour: Throws exception
  • Actual behaviour: Run smoothly

Reproduces how often
100%

Version
ALL

Additional Information
[Any additional information, configuration or data that might be necessary to reproduce the issue]

Spring boot executable jar application does not see classes with ChagneLogs

When our application is packaged as executable spring boot jar ChangeLog classes inside this jar are not seen. It was working in version 3.0.0-BETA. It looks like changes in: 20fe854 in method fetchChangeLogs causes the problem

With prior versions this was working well and also when the application is not packaged as spring-boot than ChangeLogs are also seen with no problems.

Display more meaningful logs when applying changes

Logs displayed when applying changes are not helpful. They show something like that: com.github.cloudyrock.mongock.ChangeEntry@66a3c1f8 applied which does't say which change it refers to. It would be better if it included more meaningful information, like the change id

Mongo SNAPSHOT not avalable on oss.sonatype snapshots repositories

I had this:

  <repositories>
        <repository>
            <id>sonatype-releases</id>
            <url>https://oss.sonatype.org/content/repositories/releases</url>
        </repository>
        <repository>
            <id>sonatype-snapshots</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </repository>
    </repositories>

but you do not deploy on oss.sonatype snapshots repositories

Do you want any help for this?

Illegal Reflective Access Warning with Java 9+

Info

  • mongock-core 2.0.0
  • mongock-spring 2.0.0
  • Java(TM) SE Runtime Environment 18.9 (build 11.0.3+12-LTS)

Description
After upgrading our project from JDK8 to JDK11, the JVM prints an illegal reflective access warning when Mongock is initialized:

WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/C:/Users/USER/.gradle/caches/modules-2/files-2.1/cglib/cglib/3.2.12/16c0d1d8b5d50ea9ad38c1f6f9f1e35a42727bf0/cglib-3.2.12.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
	at net.sf.cglib.core.ReflectUtils$1.run(ReflectUtils.java:61)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at net.sf.cglib.core.ReflectUtils.<clinit>(ReflectUtils.java:52)
	at net.sf.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:243)
	at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
	at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:332)
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:96)
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:94)
	at net.sf.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
	at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
	at net.sf.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
	at net.sf.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:119)
	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:294)
	at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221)
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:174)
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:153)
	at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:73)
	at com.github.cloudyrock.mongock.ProxyFactory.createProxyClass(ProxyFactory.java:59)
	at com.github.cloudyrock.mongock.ProxyFactory.createProxyFromOriginal(ProxyFactory.java:105)
	at com.github.cloudyrock.mongock.SpringMongockBuilder.build(SpringMongockBuilder.java:98)
	at com.github.cloudyrock.mongock.SpringMongockBuilder.build(SpringMongockBuilder.java:13)

WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

At the moment this doesn't seem to be too critical, however I'm concerned about the last statement (future Java releases will deny that kind of operation).

Reproduce
I've prepared a small sample project which reproduces the issue:
https://github.com/lukaseckert/mongock_reflectaccess
Make sure to set JAVA_HOME to JDK11, then run
./gradlew bootRun

Further information
Other projects seem to have experienced the same issue in the past, see

Problem with replaceOne with upsert

I have a problem using MongoCollection.replaceOne method in Mongock ChangeSet methods. When I do something like this:

@ChangeSet(id = "test-replace", order = "001")
public void testReplace(MongoDatabase db) {
	MongoCollection<Document> testCollection = db.getCollection("TestCollection");
	Document testDocument = new Document("_id", "testId").append("testField", "testValue");
	testCollection.replaceOne(eq("_id", "testId"), testDocument, 
		ReplaceOptions.createReplaceOptions(new UpdateOptions().upsert(true)));
}

I get an exception:

[INFO] Caused by: java.lang.reflect.InvocationTargetException: null
[INFO] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[INFO] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[INFO] 	at java.lang.reflect.Method.invoke(Method.java:498)
[INFO] 	at com.github.cloudyrock.mongock.SpringBootMongock.executeChangeSetMethod(SpringBootMongock.java:66)
[INFO] 	at com.github.cloudyrock.mongock.Mongock.executeIfNewOrRunAlways(Mongock.java:128)
[INFO] 	at com.github.cloudyrock.mongock.Mongock.executeMigration(Mongock.java:112)
[INFO] 	... 176 common frames omitted
[INFO] Caused by: java.lang.AbstractMethodError: Method com/github/cloudyrock/mongock/decorator/impl/MongoCollectionDecoratorImpl.replaceOne(Lorg/bson/conversions/Bson;Ljava/lang/Object;Lcom/mongodb/client/model/ReplaceOptions;)Lcom/mongodb/client/result/UpdateResult; is abstract
[INFO] 	at com.github.cloudyrock.mongock.decorator.impl.MongoCollectionDecoratorImpl.replaceOne(MongoCollectionDecoratorImpl.java)
[INFO] 	at pl.test.TestMigrations.testReplace(TestMigrations.java:33)
[INFO] 	... 183 common frames omitted

The line that the exception points to (TestMigrations.java:33) is the line with testCollection.replaceOne method

This error occurs only when I am using replaceOne with upsert, when I use replaceOne without ReplaceOptions the migration runs without problem.

I am using com.github.cloudyrock.mongock:mongock-spring in version 3.0.3.BETA

MongoConverter support in Spring Modules

Hi,
I have some problems with mongock.
It seems that MongoTemplateDecoratorImpl doesn't catch

    @Bean
    public MongoCustomConversions mongoCustomConversions() {
        return new MongoCustomConversions(Arrays.asList(
                new BigDecimalDecimal128Converter(),
                new Decimal128BigDecimalConverter()
        ));

    }

and in the end i receive this exception:

Caused by: com.github.cloudyrock.mongock.MongockException: No converter found capable of converting from type [org.bson.types.Decimal128] to type [java.math.BigDecimal]
	at com.github.cloudyrock.mongock.Mongock.executeMigration(Mongock.java:119) ~[mongock-core-3.0.2.BETA.jar:na]
	at com.github.cloudyrock.mongock.Mongock.execute(Mongock.java:62) ~[mongock-core-3.0.2.BETA.jar:na]
	at com.github.cloudyrock.mongock.SpringBootMongock.run(SpringBootMongock.java:40) ~[mongock-spring-3.0.2.BETA.jar:na]
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:809) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
	... 5 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
	at com.github.cloudyrock.mongock.SpringBootMongock.executeChangeSetMethod(SpringBootMongock.java:66) ~[mongock-spring-3.0.2.BETA.jar:na]
	at com.github.cloudyrock.mongock.Mongock.executeIfNewOrRunAlways(Mongock.java:128) ~[mongock-core-3.0.2.BETA.jar:na]
	at com.github.cloudyrock.mongock.Mongock.executeMigration(Mongock.java:112) ~[mongock-core-3.0.2.BETA.jar:na]
	... 8 common frames omitted
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.bson.types.Decimal128] to type [java.math.BigDecimal]
	at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321) ~[spring-core-5.0.9.RELEASE.jar:5.0.9.RELEASE]
	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194) ~[spring-core-5.0.9.RELEASE.jar:5.0.9.RELEASE]
	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:174) ~[spring-core-5.0.9.RELEASE.jar:5.0.9.RELEASE]
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getPotentiallyConvertedSimpleRead(MappingMongoConverter.java:908) ~[spring-data-mongodb-2.0.10.RELEASE.jar:2.0.10.RELEASE]
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readValue(MappingMongoConverter.java:1412) ~[spring-data-mongodb-2.0.10.RELEASE.jar:2.0.10.RELEASE]
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:1355) ~[spring-data-mongodb-2.0.10.RELEASE.jar:2.0.10.RELEASE]
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readProperties(MappingMongoConverter.java:336) ~[spring-data-mongodb-2.0.10.RELEASE.jar:2.0.10.RELEASE]
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:292) ~[spring-data-mongodb-2.0.10.RELEASE.jar:2.0.10.RELEASE]
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:245) ~[spring-data-mongodb-2.0.10.RELEASE.jar:2.0.10.RELEASE]
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:194) ~[spring-data-mongodb-2.0.10.RELEASE.jar:2.0.10.RELEASE]
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:190) ~[spring-data-mongodb-2.0.10.RELEASE.jar:2.0.10.RELEASE]
	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:78) ~[spring-data-mongodb-2.0.10.RELEASE.jar:2.0.10.RELEASE]
	at org.springframework.data.mongodb.core.MongoTemplate$ReadDocumentCallback.doWith(MongoTemplate.java:2800) ~[spring-data-mongodb-2.0.10.RELEASE.jar:2.0.10.RELEASE]
	at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:2463) ~[spring-data-mongodb-2.0.10.RELEASE.jar:2.0.10.RELEASE]
	at org.springframework.data.mongodb.core.MongoTemplate.findAll(MongoTemplate.java:1650) ~[spring-data-mongodb-2.0.10.RELEASE.jar:2.0.10.RELEASE]
	at com.github.cloudyrock.mongock.decorator.impl.MongoTemplateDecoratorImpl.lambda$findAll$61(MongoTemplateDecoratorImpl.java:420) ~[mongock-spring-3.0.2.BETA.jar:na]
	at com.github.cloudyrock.mongock.decorator.util.MethodInvokerImpl.invoke(MethodInvokerImpl.java:18) ~[mongock-core-3.0.2.BETA.jar:na]
	at com.github.cloudyrock.mongock.decorator.impl.MongoTemplateDecoratorImpl.findAll(MongoTemplateDecoratorImpl.java:420) ~[mongock-spring-3.0.2.BETA.jar:na]
	at org.springframework.data.mongodb.core.MongoTemplate.findAll(MongoTemplate.java:1645) ~[spring-data-mongodb-2.0.10.RELEASE.jar:2.0.10.RELEASE]
	at com.github.cloudyrock.mongock.decorator.impl.MongoTemplateDecoratorImpl.lambda$findAll$60(MongoTemplateDecoratorImpl.java:415) ~[mongock-spring-3.0.2.BETA.jar:na]
	at com.github.cloudyrock.mongock.decorator.util.MethodInvokerImpl.invoke(MethodInvokerImpl.java:18) ~[mongock-core-3.0.2.BETA.jar:na]
	at com.github.cloudyrock.mongock.decorator.impl.MongoTemplateDecoratorImpl.findAll(MongoTemplateDecoratorImpl.java:415) ~[mongock-spring-3.0.2.BETA.jar:na]

dependency version:
compile 'com.github.cloudyrock.mongock:mongock-spring:3.0.2.BETA'
Spring Boot 2.0.5.RELEASE

Add jacoco support for local and sonarcloud analysys

Requirements:

  • Provide jacoco initial configuration for multi-project
  • Provide minimum threshold for test coverage(initially can be per project or shared)
  • Provide support to run jacoco locally and make it fails if the minimum test coverage is not achieved

Initially all tests(unit and integration tests) are grouped together. But next step is separate them, so they can be analysed separately and have different thresholds.

Spring Boot 1.15.11: `java.lang.ExceptionInInitializerError`

I'm trying to migrate a project over from Mongobee to Mongock, so far I've stripped all Mongobee refs out and dropped in Mongock like this:

@Autowired
  public MongockMigrator(final MongoClient mongoClient,
                         final MongoTemplate mongoTemplate) {
    this.mongoTemplate = mongoTemplate;
    this.mongoClient = mongoClient;
  }

  @Override
  public void run(final String... strings) throws Exception {
    final Mongock runner = buildRunner();
    applyMigrations(runner);
  }

  private Mongock buildRunner() {
    return new MongockBuilder(
        this.mongoClient,
        this.mongoTemplate.getDb().getName(),
        ROOT
    ).build();
  }

  private static void applyMigrations(final Mongock runner) {
    runner.execute();
  }

However whenever I start up Spring I get: java.lang.ExceptionInInitializerError: null (happy to share more of the stack trace). I've made sure all of our existing @ChangeLogs and @ChangeSets are pointing to Mongock, and I've binary searched through some of the Mongock releases (1.16.2, 2.0.0, 2.0.2, 3.1.0-BETA) but can't seem to get past it.

Currently importing like this:
dependency 'com.github.cloudyrock.mongock:mongock-spring:1.16.2' in a main gradle file, and compile 'com.github.cloudyrock.mongock:mongock-spring:1.16.2' in the module gradle file

Support for metadata in mongockChangeLog documents

I has come up as requirement the need of having some way of tagging executions with some metadata.

This metadata would be added in the builder as execution time and propagated to each item in the collection mongoChangeLog.

Add test coverage

Currently the test coverage is not great. It's important to add test and provide a 80%-90% coverage.
Jacoco is a good tool to validate this

Use mongock with springboot 2.0.7 but do not work

I copy/pase your sample:

@Bean
public SpringBootMongock mongock(ApplicationContext springContext, MongoClient mongoClient) {
  return new SpringBootMongockBuilder(mongoClient, "yourDbName", "com.package.to.be.scanned.for.changesets")
      .setApplicationContext(springContext) 
      .setLockQuickConfig()
      .build();
}

but I need add a cast:

@Bean
public SpringBootMongock mongock(ApplicationContext springContext, MongoClient mongoClient) {
  return (SpringBootMongock) new SpringBootMongockBuilder(mongoClient, "yourDbName", "com.package.to.be.scanned.for.changesets")
      .setApplicationContext(springContext) 
      .setLockQuickConfig()
      .build();
}

and after I had this problem:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongock' defined in class path resource [com/myproject/user/configuration/MongoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.mongock.SpringBootMongock]: Factory method 'mongock' threw exception; nested exception is java.lang.ExceptionInInitializerError
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:591) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1246) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]
	at com.myproject.user.UserServerApplication.main(UserServerApplication.java:19) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.mongock.SpringBootMongock]: Factory method 'mongock' threw exception; nested exception is java.lang.ExceptionInInitializerError
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:583) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	... 18 common frames omitted
Caused by: java.lang.ExceptionInInitializerError: null
	at com.github.cloudyrock.mongock.ProxyFactory.createProxyClass(ProxyFactory.java:58) ~[mongock-core-1.16.1.jar:na]
	at com.github.cloudyrock.mongock.ProxyFactory.createProxyFromOriginal(ProxyFactory.java:99) ~[mongock-core-1.16.1.jar:na]
	at com.github.cloudyrock.mongock.SpringBootMongockBuilder.build(SpringBootMongockBuilder.java:80) ~[mongock-spring-1.16.1.jar:na]
	at com.github.cloudyrock.mongock.SpringBootMongockBuilder.build(SpringBootMongockBuilder.java:15) ~[mongock-spring-1.16.1.jar:na]
	at com.myproject.user.configuration.MongoConfiguration.mongock(MongoConfiguration.java:35) ~[classes/:na]
	at com.myproject.user.configuration.MongoConfiguration$$EnhancerBySpringCGLIB$$cc3decd7.CGLIB$mongock$0(<generated>) ~[classes/:na]
	at com.myproject.user.configuration.MongoConfiguration$$EnhancerBySpringCGLIB$$cc3decd7$$FastClassBySpringCGLIB$$c35f50f6.invoke(<generated>) ~[classes/:na]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	at com.myproject.user.configuration.MongoConfiguration$$EnhancerBySpringCGLIB$$cc3decd7.mongock(<generated>) ~[classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]
	... 19 common frames omitted
Caused by: java.lang.IllegalArgumentException: null
	at org.objectweb.asm.ClassVisitor.<init>(Unknown Source) ~[asm-5.0.4.jar:5.0.4]
	at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:49) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.DefaultGeneratorStrategy.getClassVisitor(DefaultGeneratorStrategy.java:30) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:329) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[cglib-3.2.7.jar:na]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_191]
	at net.sf.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:174) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:153) ~[cglib-3.2.7.jar:na]
	at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:73) ~[cglib-3.2.7.jar:na]
	... 34 common frames omitted

Startup error with JHipster

I am trying to use mongock as a replacement for Mongobee in a Jhipster application. I have added the following code in place of the Mongobee bean:

    @Bean
    public Mongock mongock(ApplicationContext ctx, MongoClient mongoClient, MongoProperties mongoProperties, MongoTemplate mongoTemplate) {
        return new SpringBootMongockBuilder(mongoClient, mongoProperties.getMongoClientDatabase(), "com.elvtn.config.dbmigrations")
            .setApplicationContext(ctx)
            .setLockQuickConfig()
            .setEnabled(true)
            .build();
    }

When I run my application, I get this error on startup:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongock' defined in class path resource [com/elvtn/config/DatabaseConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.mongock.Mongock]: Factory method 'mongock' threw exception; nested exception is java.lang.ExceptionInInitializerError
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:333)
	at com.elvtn.App.main(App.java:62)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.mongock.Mongock]: Factory method 'mongock' threw exception; nested exception is java.lang.ExceptionInInitializerError
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582)
	... 21 common frames omitted
Caused by: java.lang.ExceptionInInitializerError: null
	at com.github.cloudyrock.mongock.ProxyFactory.createProxyClass(ProxyFactory.java:58)
	at com.github.cloudyrock.mongock.ProxyFactory.createProxyFromOriginal(ProxyFactory.java:99)
	at com.github.cloudyrock.mongock.SpringBootMongockBuilder.build(SpringBootMongockBuilder.java:80)
	at com.github.cloudyrock.mongock.SpringBootMongockBuilder.build(SpringBootMongockBuilder.java:15)

This is with JDK8, JHipster 5.5, and Spring Boot 2.

Am initializing the mongock bean properly?

package mongock annotations in a separate module

Currently mongock annotations (@ChangeLog and @Changeset) are packaged as part of 'mongock-core' module, in use cases where change sets are defined and executed by different applications or processes, including the 'mongock-core' dependency brings in dependencies which are not really required for authoring change sets.

If the annotations are packaged in a separate module, it will help with separation of concerns and avoid unintended transitive dependency conflicts.

@Profile with SpringBootMongock

Hi,
I configured SpringBootMongock like :

@Bean
    public SpringBootMongock mongock(ApplicationContext springContext, MongoClient mongoClient, MongoProperties mongoProperties) {
        return new SpringBootMongockBuilder(mongoClient, mongoProperties.getDatabase(), "my.package")
                .setApplicationContext(springContext)
                .setLockQuickConfig()
                .build();
    }

And ChangeLog :

@ChangeLog
@Profile({"!test", "!dataset"})
public class DatabaseChangelog {
...
}

When I'm running tests with @ActiveProfiles("test"), Mongock is executed.
Method .setSpringEnvironment(environment) of SpringMongock is not implemented in SpringBootMongock
Did I miss something to handle my profile ?

Use MongoTemplate rather than MongoClient to instantiate a new Mongock

In SpringBoot projects, the only Bean we can autowire would be the MongoTemplate itself, from which seems pretty tricky (and pointless) to extract a new MongoClient. Please add the ability to instantiate a new Mongock directly with a MongoTemplate, at least for the SpringMongockBuilder.

versioning and runAlways issues

How is the versioning supposed to work? If I update the change-set version (in the annotation), it is NOT being re-executed. I do have the builder set with the correct start/end version range.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.