2

Is there a way to configure liquibase to run different sql scripts test vs prod with maven?

3
  • That seems like a bad idea, then you haven't necessarily run and tested those scripts before trying to do so in prod. This may be an XY problem; what's the problem you're trying to solve with this? Commented May 7, 2020 at 6:44
  • 1
    To add dummy data into the test database and to avoid doing that in prod environment. Commented May 7, 2020 at 6:48
  • 1
    Perhaps that should be a separate task to migrating? This is usually referred to as seeding. Commented May 7, 2020 at 6:49

1 Answer 1

2

To solve the problem you can use Liquibase context. It allows you to execute only specific changeSets which are related to the provided context.

For maven you can use -Dliquibase.contexts=test_context

If you have a Spring applications, you can use spring.liquibase.contexts=test_context

And in changeSets set context attribute:

<changeSet id="foo" author="bat" context="text_context">
   <!-- your logic here -->
</changeSet>
Sign up to request clarification or add additional context in comments.

2 Comments

Here's a link that may help as well: liquibase.org/2014/11/contexts-vs-labels.html It is context vs labels and outlines the way liquibase can control which script in which environment will get ran, and includes when to use either context, label, or both.
Works like a charm! You can also use labels instead of contexts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.