Custom hook before update run

How to to add the custom hook java file should be run before executing the liquibase update .
We need some custom hook to generate the liquibase format file from json format. before running the update statement

We have a relatively new “command pipeline” system which should work, but since it’s new and in beta it’s not well documented yet.

But, there is CommandStep (liquibase 4.7.0 API) (and the AbstractCommandStep convenience class) allows you to plug into the commands you like. They work a lot like a ServletFilter.

You would implement the getOrder method to return when to run. In your case, you’d return ORDER_NOT_APPLICABLE if the command is not “update” and something lower than ORDER_DEFAULT (like ORDER_DEFAULT-10) for “update” so it runs before the normal UpdateCommandStep.

Then you can implement what you want in the run(CommandResultsBuilder) method.

This new “command framework” isn’t fully hooked up in all the integrations yet, however. It is most supported in the CLI and direct java API calls that use it. If you were using something like maven or spring, however, there are hooks outside of liquibase which you can use.

Does that work for you?


We are using spring. Can you please explain how we can using hook from outside?

Am new to liquibase so please explain in details so that i can try in project.

If you’re using spring, there is probably an better way yet. By default, spring uses a liquibase.integration.spring.SpringLiquibase which does it’s logic in the afterPropertiesSet() method.

But, you can change the implementation of SpringLiquibase used by spring to be a subclass you create which overrides the afterPropertiesSet() to do whatever logic you need before calling super.afterPropertiesSet().

Something like:

public class SpringLiquibaseConfig {

    private final DataSource dataSource;
    private final Environment environment;

    public SpringLiquibaseConfig(DataSource dataSource, Environment environment) {
        this.dataSource = dataSource;
        this.environment = environment;

    public SpringLiquibase liquibase() {
        MySpringLiquibase liquibase = new MySpringLiquibase();
        return liquibase;