Liquibase execution on specific enviroment(maven + spring boot)

Viewed 1442

My apllication(maven + spring boot) have a liquibase, but I need execute only on dev enviroment. On another enviroments(prod, CI for example) I'll need block the execution.

Can I do this?

tks.

2 Answers

There're two options:

  1. For your prod environment you can use spring.liquibase.enabled=false properties. This will disable Liquibase altogether and no changeSet will be executed.

  2. Use Liquibase contexts. When executing maven scripts you can add -Dliquibase.contexts=dev_context property (for spring-boot it'll be spring.liquibase.contexts=dev_context).

And in your changeSets you can specify the context attribute:

<changeSet id="foo" author="bar" context="dev_context">
   <!-- your logic here -->
</changeSet>

This way your changeSet will be executed only for dev_context.

Tks for the answer

I try this but didn't work.

I think the probleam is on my pom.xml. If e delete the tag, the liquibase don't work.

                <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>3.8.4</version>
                <configuration>
                    <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                    <propertyFile>src/main/resources/liquibase.properties</propertyFile>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>update</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
Related