多个数据库上的Liquibase [英] Liquibase on multiple databases

查看:726
本文介绍了多个数据库上的Liquibase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用Maven实现了Liquibase.我们当前使用的是单个数据库(db2),但是现在我们需要向应用程序中添加一个具有不同对象的新数据库.

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.

我已经看到我可以在Maven中定义一个新的配置文件,但是我找不到如何区分在哪个数据库上创建哪些对象的方法.

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.

有解决方案吗?我可以使用liquibase支持2个具有不同对象的不同数据库吗?

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>

这种方法的唯一问题是,您需要两个不同的changelog.xml文件,每个数据库一个.

The only problem with this approach is that you need two different changelog.xml files, one per database.

此外,您还可以在变更日志文件中使用前提条件来在之间进行选择. > changeset 将由每个数据库处理.

Also, you can have preconditions in your changelog file to choose between what changeset will be processed by each database.

例如:

<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>

onFail="MARK_RAN"使Liquibase跳过更改集,但将其标记为已运行,因此下次将不再重试.有关更复杂的先决条件,请参见文档中的customPrecondition标记.

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.

这篇关于多个数据库上的Liquibase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆