0

My local deployment application supports 2 database types (Oracle and MS Sql Server). I have a working system with a set of build scripts that can be run against an empty schema to create a new build. I now want to support versioning; so when I update the schema it's recorded and a user can run any updates since their last update to the DB to catch up with the code.

Is Liquibase capable of managing two databases and outputting update scripts based on version numbers?

I'm not too familiar with Liquibase and most demos and tutorials just show basic versioning with a single database.

2 Answers 2

2

Yes there is a way to do this. You can add dbms="postgresql" in the Tag of a changeSet. The cangeSet will now only be executed on postgresql databases.

<changeSet id="someCustomId-123" author="authorName" dbms="postgresql">
    <addColumn tableName="someTable">
        <column name="someColumnName" type="tsvector"/>
    </addColumn>
</changeSet>

This is particularly usefull when you Databases require different syntax the same functionality (like timestamps and such)

The Addition of "dbms" in a changeset will not change its md5 Hash Value. So this can be done even if one Database is already used and contains several changeSets.

The documentation and syntax for the types of databases can be found here https://docs.liquibase.com/concepts/changelogs/changelog-formats.html

https://www.liquibase.org/get-started/databases?_ga=2.155505784.297037967.1649459316-293111970.1649459316

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much, I can spend my weekend stress-free.
0

It looks like this question was answered in an earlier thread. There are a couple of different solutions in the answers, but I'll summarize the answer with the highest votes.

  • As you can see in the documentation, you can use two different executions:
    <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.

Reference

StackOverflow: Liquibase on multiple databases

Comments

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.