I want to my company to use LiquiBase, but I’m trying to understand how to use it for our situation.
We produce an enterprise product that is installed at customer sites. Customers install their own upgrades.
We use Spring and Hibernate. I want LiquiBase updates to use the SpringLiquibase bean, in other words, the updates happen when the webapp starts up. I like this approach, because the Java team can own all db updates, and we don’t have to get our platform team involved. However, I don’t think this is possible: Say we are modifying a db column. The Hibernate definition for the new release will use the new definition of that column, and I believe Hibernate will always run before the SpringLiquibase bean. The webapp will fail to start because the db still has the old column definition. In other words, the only option is to run a command line LiquiBase update before the webapp starts, before Hibernate starts. So the SpringLiquibase bean is not an option for us. Am I correct?
You definitely would need to have liquibase run before hibernate, but that should be possible to configure. Is hibernate managed by spring as well?
I don’t know the syntax off hand for how to control what beans are created in what order within spring, but it probably depends on the version of spring and/or how you have it configured.
Another option would be to use the servlet listener liquibase runner, that can allow liquibase to run before spring even starts.
You can still use the Spring Liquibase bean and make sure it is created before hibernate by using the depends-on attribute. This attribute allows you to manually create a dependency on another bean without directly injecting it. This is how I use it because it allows me to reference my change log using Spring’s excellent Resource/IO prefixes. Here is an example: