I have already implemented Liquibase with Maven. We are currently using a single database (db2) but now we need to add a new database to the application which will have different objects.
I've seen that i can define a new profile in maven but i couldn't find out how to differentiate which objects is being created on which database.
Is there a solution to this? Can I support 2 different databases with different objects using liquibase?
As you can see in the documentation, you can use two different executions, like this:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.0.5</version>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<changeLogFile>PATH_TO_CHANGELOG_1</changeLogFile>
... connection properties ...
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
<execution>
<phase>process-resources</phase>
<configuration>
<changeLogFile>PATH_TO_CHANGELOG_2</changeLogFile>
... connection properties ...
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
The only problem with this approach is that you need two different changelog.xml
files, one per database.
Also, you can have preconditions in your changelog file to choose between what changeset will be processed by each database.
For example:
<changeSet id="1" author="bob">
<preConditions onFail="MARK_RAN">
<dbms type="oracle" />
</preConditions>
<comment>Comments should go after preCondition. If they are before then liquibase usually gives error.</comment>
<dropTable tableName="oldtable"/>
</changeSet>
The onFail="MARK_RAN"
makes Liquibase skip the changeset but marks it as run, so the next time it will not try again. See the customPrecondition
tag in the documentation for more complex preconditions.
You may want to have 2 separate changelogs to manage the two databases, even if they are both used by the same application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With