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

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

Closed
torr-penn opened this issue May 30, 2022 · 2 comments
Closed

Comments

@torr-penn
Copy link

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: - @ConditionalOnMissingBean (types: liquibase.integration.spring.SpringLiquibase,net.lbruun.springboot.preliquibase.PreLiquibase; SearchStrategy: all) found beans of type 'liquibase.integration.spring.SpringLiquibase' liquibase (OnBeanCondition) Matched: - @ConditionalOnClass found required classes 'liquibase.integration.spring.SpringLiquibase', 'liquibase.change.DatabaseChange' (OnClassCondition)
Solution if anyone face this problem : simply remove LiquibaseConfiguration.java from jhipster generated code and
rely on your jhipster application-dev.yml configuration file to setup preliquibase and liquibase.

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

@lbruun
Copy link
Owner

lbruun commented May 30, 2022

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.

@lbruun lbruun closed this as completed May 30, 2022
@torr-penn
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants