1

Is it possible to use Liquibase just to check the consistency of the database?

We have several java application modules using the same database. We decided that only one of the modules is responsible for the execution of database migrations, while the other modules (several batch jobs) include the scripts as a dependency. For the batch job modules we want to prevent the migration of the database schema, but we need to be sure that the code base uses the same version as the database.

Is it possible to configure liquibase in a way to perform the validation but not the migration?

We want to try this approach because the migration of two modules starting at the same time caused conflicts that prevented the application from starting.

ABKN
  • 59
  • 5

2 Answers2

0

It's possible to use Liquibase for DB schema validation, however it wasn't quite designed for this.

So, for instance, if you want to always check weather certain table exists or not, you can do the following:

<changeSet author="author_name" id="changeset_id" runAlways="true">
    <preConditions onFail="HALT">
        <tableExists tableName="foo_bar"/>
    </preConditions>
    <comment>Table "foo_bar" exists.</comment>
</changeSet>

This changeSet doen't do anything but checking that foo_bar table exists.

runAlways="true" attribute will tell Liquibase to execute the changeSet every time the application starts.

onFail="HALT" will throw an error if foo_bar table doesn't exist, hence if preConditions weren't met.

htshame
  • 6,599
  • 5
  • 36
  • 56
0

You can use the liquibase status command to check that all changesets listed in the changelog have been applied, and add the --verbose flag to that to see which changesets have not been applied.

This does not ensure that no drift has happened though - it is certainly possible for someone to manually alter the database and make changes that cause the status command to be inaccurate. As long as you are generally confident that schema changes are always made through liquibase, the status command should be sufficient.

SteveDonie
  • 8,700
  • 3
  • 43
  • 43