【问题标题】:Is it possible to change database connections between changesets in Liquibase?是否可以更改 Liquibase 中变更集之间的数据库连接?
【发布时间】:2021-08-29 23:59:23
【问题描述】:

我已经查看了 Liquibase changesetscustomChangecontexts,但是在阅读了这几天的材料之后,我仍然没有找到可以帮助我完成我想做的事情的答案.

基本上,我有想要通过 Liquibase 运行的数据库更改脚本。这就是我所拥有的。

  1. script1.sql
    • DROP MATERIALIZED VIEW LOG on TABLE1
  2. script2.sql
    • DROP MATERIALIZED VIEW TABLE1

script1.sql 应该在某个DB1 上运行,而script2.sql 应该在某个DB2 上运行。 DB1DB2 的数据库 URL 是:

  1. DB1: 'jdbc:oracle:thin:@db_host:1521:DB1'
  2. DB2: 'jdbc:oracle:thin:@db_host:1521:DB2'

我有 ff。定义在build.gradle:

liquibase {
  activities {
    main {
      changeLogFile "$projectDir/src/main/db/main-changelogs.xml"
      url 'jdbc:oracle:thin:@db_host:1521:DB1'
      username 'root'
      password 'root'
    }
  }
}

我的变更日志定义如下:

<?xml version="1.0" encoding="UTF-8"?> 

<databaseChangeLog  
  xmlns="http://www.liquibase.org/xml/ns/dbchangelog" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  xmlns:pro="http://www.liquibase.org/xml/ns/pro"
  xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.0.xsd
      http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-3.8.xsd">  

    <changeSet id="1" author="bob">  
        <sqlFile dbms="oracle"
          path="my/path/script1.sql" />
    </changeSet>  
    <changeSet id="2" author="bob">  
        <sqlFile dbms="oracle"
          path="my/path/script2.sql" />
    </changeSet>  

</databaseChangeLog>

因此我的问题是,如何在我的更新日志中切换DB1DB2 之间的连接?

【问题讨论】:

    标签: java sql oracle gradle liquibase


    【解决方案1】:

    据我所知,您可能希望有 2 个不同的 liquibase.properties 文件来指定数据库 url。此外,如果您只使用 1 个变更日志文件,则可以使用 labels,这将只允许标记的变更集针对指定的数据库运行。

    【讨论】:

      【解决方案2】:

      我也在 Liquibase 论坛上回答了这个问题...

      您不能在 Liquibase 的执行中更改连接。

      我建议分成两个变更日志并运行两个 Liquibase 部署,一个用于 DB1,一个用于 DB2。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-07-10
        • 1970-01-01
        • 2012-07-11
        • 1970-01-01
        • 2018-11-03
        • 2010-11-04
        • 1970-01-01
        相关资源
        最近更新 更多