Search code examples
spring-bootliquibase

Execute liquibase SQL query only againt local DB


I have a Spring Boot application which uses liquibase to track and version DB changes. I am using xml files where I define the changesSets.

I need to add one insert into statement which I need to execute against the local developer DB.

Is there a way to execute this SQL query adding some kind of condition so that it gets executed only if the DB is the local one?


Solution

  • You may use liquibase contexts for that.

    Just specify the liquibase context in your local application.properties file:

    spring.liquibase.contexts=local
    

    And specify the context to the needed changeSet:

    <changeSet id=“foo” author=“bar” context=“local”>
        — logic for local db 
    </changeSet>