Check that the changelog and the database are equal

I originally posted this question on stackoverflow, but since there was not so much activity, I thought it’s a good idea to post this here as well.

My usecase: We use liquibase to manage the database layout and its changes. We also use liquibase to generate SQL scripts based on the liquibase changeset that are given to the customers. Our application however does not use liquibase to generate the schema, as the application does not have the rights to do this.

What we would like to implement is that the application checks on startup if the bundled changeset is equal to the database schema and the startup is aborted if they do not match. Is there a function in the liquibase Java API that I can use for that?

Thanks and best regards

Hello @benny

I don’t think we would be able to compare a changelog file (XML/SQL/JSON/YAML) with a database instance using liquibase.
Similar question has been asked earlier where different usage patterns of liquibase are provided in the answer. May be you could try and think of some other way to abort the application startup.

Rakhi Agrawal

Hello @rakhi

Thank you for your answer.

To be honest, I don’t really understand why liquibase shouldn’t be able to compare the changelog and the database.

Just for clarification, the database scripts that are executed before the application is started, are generated by liquibase. They contain the statements to create and insert into the DATABASECHANGELOG and -LOCK table, and they are filled with the changesets from the changelog file. As far as i can tell, the database looks exactly the same as if liquibase update would have been executed.

In my understanding, liquibase does not need to evaluate the schema layout and try to match that with the changelog file. It just needs to compare the content of the DATABASECHANGELOG table with the changelog file and tell me if they are identical or not.

Am I wrong in my understanding or missing something?

Hello everyone,

an answer to this question would be very much appreciated.


After digging through the liquibase source code, I found the method that I was looking for:

liquibase.listUnrunChangeSets(null, null);

This is exactly what I wanted it seems to be working fine.

1 Like

The Liquibase command “status --verbose” will also show the changsets that are pending (“unrun”).

Great! Thanks for sharing. Would prove helpful for others as well.