lbruun-net / Pre-Liquibase

Spring Boot add-on to Liquibase
Apache License 2.0
49 stars 9 forks source link

investigation not easy when Liquibase is activated before Pre-Liquibase #5

Closed torr-penn closed 2 years ago

torr-penn commented 2 years ago

It's not a real issue but a behavior of the library.

In the context of a simple jhipster/postgresql generated application 7.8.1, liquibase is already in place which is nice.

Unfortunately a LiquibaseConfiguration.java file is generated and prevents in my case the execution of pre-liquibase "Create schema"script.

If possible, that could be nice to have a more explicit warning or logs to investigate such case that liquibase was pre-loaded.

In my case, investigation was made from activation of : org.springframework.boot.autoconfigure: DEBUG

that provides this information : ` PreLiquibaseAutoConfiguration: Did not match:

Thanks lbruun for the library. I let you close the issue once you got this suggestion.

lbruun commented 2 years ago

So, in essence you are saying that the source code generated by JHipster configures a bean of type SpringLiquibase manually rather than relying on Spring Boot's auto-configure to do this ? (I assume this is what the LiquibaseConfiguration class that you mention does?)

If so, it makes sense.

Pre-Liquibase auto-configuration will back-off if it discovers that a bean of type SpringLiquibase already exists. This would mean that you've configured Liquibase manually rather than letting Spring Boot's auto-configure do its magic. If this is the case then Pre-Liquibase cannot figure out which DataSource you are using with Liquibase and would therefore not be able to configure itself automatically, so this is a scenario we cannot allow. If, on the other hand, you are letting the auto-configuration mechanism configure SpringLiquibase bean then we can actually predict which DataSource the SpringLiquibase bean will be using when it is eventually initiated and thereby we can auto-configure PreLiquibase bean to use the same. Pre-Liquibase was made for the lazy ones.

The morale is: If you are configuring SpringLiquibase bean manually then you must do the same for PreLiquibase bean. And you would furthermore need to annotate your custom SpringLiquibase bean with @DependsOn("preLiquibase") (actual name value depending on your Bean name) to make sure PreLiquibase bean is initiated before the SpringLiquibase bean.

There probably should be an example of using manual bean configuration with Pre-Lquibase ...when I have the time.

torr-penn commented 2 years ago

Yes you assume correctly about the role of generated LiquibaseConfiguration.java . Thank you very much for the answer, it confirms what I observed. The reason of preliquibase not activated was not obvious at first sight in my situation but it makes sense now.