Is there a way to configure liquibase to run different sql scripts test vs prod with maven?
-
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?jonrsharpe– jonrsharpe2020-05-07 06:44:39 +00:00Commented May 7, 2020 at 6:44
-
1To add dummy data into the test database and to avoid doing that in prod environment.matheo– matheo2020-05-07 06:48:34 +00:00Commented May 7, 2020 at 6:48
-
1Perhaps that should be a separate task to migrating? This is usually referred to as seeding.jonrsharpe– jonrsharpe2020-05-07 06:49:52 +00:00Commented May 7, 2020 at 6:49
Add a comment
|
1 Answer
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>
2 Comments
ronak
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.
ru51an
Works like a charm! You can also use labels instead of contexts