Maven Liquibase update command executes changeSet again even after getting executed on start-up

Hi,

Liquibase runs on start-up in springboot application and executes all the new changeSets.
When i run mvn liquibase:update without any changes in changeLog file, it runs all the changesets again and throws liquibase.exception.DatabaseException since the table already exists.
The changeSet does not get executed when i re-run the application.

When i update changeSet using maven command before running the application, it works as expected. But if i run application after executing mvn liquibase:update command it runs the changesSet again and throws error

mvn liquibase:history command shows all the executed changeSets which got executed on start-up.

mvn liquibase:rollbackSQL --Dliquibase.rollbackCount=1 does not generate the expected rollback sql file.
mvn liquibase:rollback --Dliquibase.rollbackCount=1 command does not behave as expected

Has anyone encountered this? Do you have a suggestion on how to solve this?

Thanks.

Hi @Krathi, that does seem like odd behaviour. The only thing I can think of is that there might be something different between the properties that are being used for running liquibase at application startup and for running the maven command.

Could you provide information about which version of Liquibase you’re using, which version of the liquibase-maven-plugin you’re using, the properties you’re using for application startup and for the maven command (are they both using the same liquibase.properties file?) and the database and version that you’re using?

Just out of interest, is there any reason why you need to be running liquibase on application startup and separately from a maven command? On the project that I work on we don’t have Liquibase running on application startup, we always manage running Liquibase separately either by devs running the maven command or if its a qa/staging/prod environment then Liquibase is run separately as part of the CI/CD pipeline. There’s no reason why you shouldn’t be able to run both as they should both work as expected, but maybe not running Liquibase at application startup is something to consider if this issue continues.

If you do want to try preventing Liquibase from running on application startup then depending on the version of Spring you’re using you can set a property in your application.properties file (or application.yaml if that’s what you’re using instead).

For the latest version of Spring you would set this:

spring.liquibase.enabled=false

For older versions of Spring you may need to use this instead:

liquibase.enabled=false

Hope that helps
Dave

Hi Dave,

Thank you for your response.

below are the details that you have asked,
liquibase - 4.4.3
liquibase maven plugin - 4.43
database - postgres
PostgreSQL -13.2

yes, both the files have same configuration.

application.properties
spring.datasource.url=jdbc:postgresql://localhost:5432/testdb
spring.datasource.username=test
spring.datasource.password=test123
spring.jpa.hibernate.ddl-auto=update
spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml
logging.level.liquibase=DEBUG

liquibase.properties
url=jdbc:postgresql://localhost:5432/testdb
username=test
password=test123
driver=org.postgresql.Driver
changeLogFile=src/main/resources/db/changelog/db.changelog-master.xml

I want to run liquibase on startup so that i don’t have to do an additional step to update database. I wanted to use maven plugin for rollback purpose.

Hi Krathi,

I’ve just created a small spring boot test application with the same settings in the application.properties and liquibase.properties as you had and with the same liquibase version but with a slightly different postgres version (I just used latest version in a docker image) and I created a couple of simple changesets to create some tables but unfortunately I couldn’t replicate your issue :confused:

It could be the postgres version that makes the difference but I can’t see why that would be the case. I’m also running on Windows and you may be running on a different OS so that also might be why I can’t replicate.

I can’t really think of any other cause of this issue so I’m a bit stumped with this one. Unless someone else on the forum can help the only other thing I can suggest is to post on the Liquibase discord to see if anyone there can help: Discord

Sorry I couldn’t be of more help with this, but I hope you manage to get to the bottom of it.
Dave

Hi Dave,

Thank you very much for your help.
I was able to find the issue. I had mentioned master file path differently in both the file i.e. application.properties and liquibase.properties because which the filename column in databasechangelog table was getting stored differently for both scenarios.

i.e db/changelog/db.changelog-master.xml when run on start-up and
src/main/resources/db/changelog/db.changelog-master.xml when run using maven.

1 Like