Liquibase命令行创建差异变更日志的SQL。

9

我实际上在Windows的命令行中使用Liquibase,并尝试创建一个表示两个数据库之间差异的SQL脚本。不幸的是,我只得到了XML文件作为返回结果。你能帮我吗?

我的命令行:

liquidbase.bat 
   --driver=com.mysql.jdbc.Driver 
   --url=jdbc:mysql://localhost:3306/base1 
   --username=root 
   diffChangeLog 
   --referenceUrl=jdbc:mysql://localhost:3306/base2 
   --referenceUsername=root 
> test.sql

我在另一个论坛上看到了类似的问题,但他没有得到好的答案(http://forum.liquibase.org/topic/convert-changelog-xml-file-into-sql-file)。 我也看过一些从updateSQL cmd获得sql文件的参数,但从未看到过diffChangeLog的参数。
XML反馈的示例:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
    <changeSet author="user (generated)" id="1370443156612-1">
        <createTable tableName="test">
            <column name="a" type="INT"/>
        </createTable>
    </changeSet>
    <changeSet author="user (generated)" id="1370443156612-2">
        <addColumn tableName="articles">
            <column name="date_debut" type="TEXT">
                <constraints nullable="false"/>
            </column>
        </addColumn>
    </changeSet>

Thanks by advance.


3
可能是[比较数据库并使用Liquibase生成SQL脚本]的重复问题。 (https://dev59.com/m2oy5IYBdhLWcg3wq_3O) - Mark O'Connor
2个回答

8

diff命令只提供文本形式的差异概述。

为了获得新(dev)和旧数据库之间差异的SQL:

  1. 使用diffChangeLog比较两个数据库,更新你的changelog(可能是暂时的)

  2. 针对过时的数据库使用updateSQL,以显示将其更新到最新状态所需运行的sql命令。请注意,打印的SQL还将包含liquibase用于管理的命令。

如果新/ dev数据库符合预期,则可以将新changelog与代码一起提交。使用changelogSync使新/ dev数据库认为已通过liquibase更新。


0
你正在运行 diffChangeLog 命令,我认为你想要的是 diff 命令?请参考 manual 中的 输出模式
liquibase.bat 
  --driver=com.mysql.jdbc.Driver 
  --url=jdbc:mysql://localhost:3306/base1 
  --username=root 
  --referenceUrl=jdbc:mysql://localhost:3306/base2 
  --referenceUsername=root 
  diff
    > test.sql

6
不是这样的,这个过程不是那么直接。不会生成任何符合SQL标准的代码,只有像@Ian Rogers所说的文本概述。 - andPat

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接