我的要求是我想比较两个数据库然后我想生成一个 diff sql。注意我只想通过 java 来做。我是 Liquibase 的新手。我找到了一个名为 CommandLineUtils 的 java api,使用它我可以生成新数据库的 changeLog。当我执行方法 doDiffToChangeLog 时,我的 changeLog xml 为空。你能告诉我哪里做错了吗。
这是我的java代码
Database database=liqui.createDatabaseObject(OracleDriver.class.getClassLoader(), "jdbc:oracle:thin:@localhost:1521:XE", "archive_pmd", "archive_pmd", "oracle.jdbc.driver.OracleDriver", "archive_pmd", null, null);
liqui.doGenerateChangeLog("test.xml", database, "archive_pmd", null, null, null, null);
Database database2=liqui.createDatabaseObject(OracleDriver.class.getClassLoader(), "jdbc:oracle:thin:@localhost:1521:XE", "archive_dbs", "archive_dbs", "oracle.jdbc.driver.OracleDriver", "archive_pmd", null, null);
liqui.doDiffToChangeLog("chageLog.xml", database2, database);
这是我生成的 test.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="DELL (generated)" id="1331066786490-1">
<createTable schemaName="archive_pmd" tableName="PMD00_SEQUENCE">
<column name="PMD00_ID" type="NUMBER">
<constraints nullable="false"/>
</column>
<column name="TABLE_IDENTIFIER" type="VARCHAR2(50 BYTE)"/>
<column defaultValueNumeric="0" name="CURRENT_VALUE" type="NUMBER">
<constraints nullable="false"/>
</column>
<column name="LAST_ACCESSED_TS" type="DATE"/>
</createTable>
</changeSet>
<changeSet author="DELL (generated)" id="1331066786490-2">
<createTable schemaName="archive_pmd" tableName="PMD01_META_DATA">
<column name="PMD01_ID" type="NUMBER">
<constraints nullable="false"/>
</column>
<column name="CATEGORY" type="VARCHAR2(30 BYTE)">
<constraints nullable="false"/>
</column>
<column name="NAME" type="VARCHAR2(50 BYTE)">
<constraints nullable="false"/>
</column>
<column name="CODE" type="VARCHAR2(100 BYTE)">
<constraints nullable="false"/>
</column>
<column name="STATUS" type="VARCHAR2(1 BYTE)">
<constraints nullable="false"/>
</column>
<column name="PMD01_METADATAVER" type="NUMBER(4,0)">
<constraints nullable="false"/>
</column>
<column name="DMLASTUPDATEDATE" type="DATE">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet author="DELL (generated)" id="1331066786490-3">
<createTable schemaName="archive_pmd" tableName="PMD13_DB_APPLICATION">
<column name="ID" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="APPLICATIONNAME" type="VARCHAR2(200 BYTE)">
<constraints nullable="false"/>
</column>
<column name="ENVIRONMENT" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="SERVERIP" type="VARCHAR2(400 BYTE)">
<constraints nullable="false"/>
</column>
<column name="USERID" type="VARCHAR2(200 BYTE)">
<constraints nullable="false"/>
</column>
<column name="PASSWORD" type="VARCHAR2(200 BYTE)">
<constraints nullable="false"/>
</column>
<column name="DBTYPE" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="DMLASTUPDATE" type="DATE">
<constraints nullable="false"/>
</column>
<column name="SERVERPORT" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="SERVICE" type="VARCHAR2(400 BYTE)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet author="DELL (generated)" id="1331066786490-4">
<createTable schemaName="archive_pmd" tableName="PMD14_DB_VERSION">
<column name="ID" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="MAJORVERSION" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="MINORVERSION" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="PATCHVERSION" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="DATEEXECUTED" type="DATE">
<constraints nullable="false"/>
</column>
<column name="DML_SCRIPT" type="BLOB">
<constraints nullable="false"/>
</column>
<column name="STATUS" type="VARCHAR2(20 BYTE)">
<constraints nullable="false"/>
</column>
<column name="REQUESTOR" type="VARCHAR2(200 BYTE)">
<constraints nullable="false"/>
</column>
<column name="DMLASTUPDATE" type="DATE">
<constraints nullable="false"/>
</column>
<column name="DML_SCRIPTNAME" type="VARCHAR2(200 BYTE)">
<constraints nullable="false"/>
</column>
<column name="DB_APPLICATION_FK" type="NUMBER">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet author="DELL (generated)" id="1331066786490-5">
<createTable schemaName="archive_pmd" tableName="PMD15_DBCOMMIT_LOG">
<column name="ID" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="MAJORVERSION" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="MINORVERSION" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="PATCHVERSION" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="DATEEXECUTED" type="DATE">
<constraints nullable="false"/>
</column>
<column name="SCRIPT" type="BLOB">
<constraints nullable="false"/>
</column>
<column name="EXECUTIONSTATUS" type="VARCHAR2(200 BYTE)">
<constraints nullable="false"/>
</column>
<column name="REQUESTOR" type="VARCHAR2(400 BYTE)">
<constraints nullable="false"/>
</column>
<column name="LOGREPORT" type="BLOB">
<constraints nullable="false"/>
</column>
<column name="DMLASTUPDATE" type="DATE">
<constraints nullable="false"/>
</column>
<column name="DBAPPLICATIONFK" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="LOGREPORTNAME" type="VARCHAR2(400 BYTE)">
<constraints nullable="false"/>
</column>
<column name="SCRIPTNAME" type="VARCHAR2(400 BYTE)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet author="DELL (generated)" id="1331066786490-6">
<createIndex indexName="SYS_C004087" schemaName="archive_pmd" tableName="PMD00_SEQUENCE" tablespace="SYSTEM" unique="true">
<column name="PMD00_ID"/>
</createIndex>
</changeSet>
<changeSet author="DELL (generated)" id="1331066786490-7">
<createIndex indexName="SYS_C004084" schemaName="archive_pmd" tableName="PMD01_META_DATA" tablespace="SYSTEM" unique="true">
<column name="PMD01_ID"/>
</createIndex>
</changeSet>
<changeSet author="DELL (generated)" id="1331066786490-8">
<createIndex indexName="SYS_C004050" schemaName="archive_pmd" tableName="PMD13_DB_APPLICATION" tablespace="SYSTEM" unique="true">
<column name="ID"/>
</createIndex>
</changeSet>
<changeSet author="DELL (generated)" id="1331066786490-9">
<createIndex indexName="SYS_C004062" schemaName="archive_pmd" tableName="PMD14_DB_VERSION" tablespace="SYSTEM" unique="true">
<column name="ID"/>
</createIndex>
</changeSet>
<changeSet author="DELL (generated)" id="1331066786490-10">
<createIndex indexName="SYS_C004076" schemaName="archive_pmd" tableName="PMD15_DBCOMMIT_LOG" tablespace="SYSTEM" unique="true">
<column name="ID"/>
</createIndex>
</changeSet>
<changeSet author="DELL (generated)" id="1331066972401-1">
<createTable schemaName="archive_pmd" tableName="PMD00_SEQUENCE">
<column name="PMD00_ID" type="NUMBER">
<constraints nullable="false"/>
</column>
<column name="TABLE_IDENTIFIER" type="VARCHAR2(50 BYTE)"/>
<column defaultValueNumeric="0" name="CURRENT_VALUE" type="NUMBER">
<constraints nullable="false"/>
</column>
<column name="LAST_ACCESSED_TS" type="DATE"/>
</createTable>
</changeSet>
<changeSet author="DELL (generated)" id="1331066972401-2">
<createTable schemaName="archive_pmd" tableName="PMD01_META_DATA">
<column name="PMD01_ID" type="NUMBER">
<constraints nullable="false"/>
</column>
<column name="CATEGORY" type="VARCHAR2(30 BYTE)">
<constraints nullable="false"/>
</column>
<column name="NAME" type="VARCHAR2(50 BYTE)">
<constraints nullable="false"/>
</column>
<column name="CODE" type="VARCHAR2(100 BYTE)">
<constraints nullable="false"/>
</column>
<column name="STATUS" type="VARCHAR2(1 BYTE)">
<constraints nullable="false"/>
</column>
<column name="PMD01_METADATAVER" type="NUMBER(4,0)">
<constraints nullable="false"/>
</column>
<column name="DMLASTUPDATEDATE" type="DATE">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet author="DELL (generated)" id="1331066972401-3">
<createTable schemaName="archive_pmd" tableName="PMD13_DB_APPLICATION">
<column name="ID" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="APPLICATIONNAME" type="VARCHAR2(200 BYTE)">
<constraints nullable="false"/>
</column>
<column name="ENVIRONMENT" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="SERVERIP" type="VARCHAR2(400 BYTE)">
<constraints nullable="false"/>
</column>
<column name="USERID" type="VARCHAR2(200 BYTE)">
<constraints nullable="false"/>
</column>
<column name="PASSWORD" type="VARCHAR2(200 BYTE)">
<constraints nullable="false"/>
</column>
<column name="DBTYPE" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="DMLASTUPDATE" type="DATE">
<constraints nullable="false"/>
</column>
<column name="SERVERPORT" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="SERVICE" type="VARCHAR2(400 BYTE)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet author="DELL (generated)" id="1331066972401-4">
<createTable schemaName="archive_pmd" tableName="PMD14_DB_VERSION">
<column name="ID" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="MAJORVERSION" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="MINORVERSION" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="PATCHVERSION" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="DATEEXECUTED" type="DATE">
<constraints nullable="false"/>
</column>
<column name="DML_SCRIPT" type="BLOB">
<constraints nullable="false"/>
</column>
<column name="STATUS" type="VARCHAR2(20 BYTE)">
<constraints nullable="false"/>
</column>
<column name="REQUESTOR" type="VARCHAR2(200 BYTE)">
<constraints nullable="false"/>
</column>
<column name="DMLASTUPDATE" type="DATE">
<constraints nullable="false"/>
</column>
<column name="DML_SCRIPTNAME" type="VARCHAR2(200 BYTE)">
<constraints nullable="false"/>
</column>
<column name="DB_APPLICATION_FK" type="NUMBER">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet author="DELL (generated)" id="1331066972401-5">
<createTable schemaName="archive_pmd" tableName="PMD15_DBCOMMIT_LOG">
<column name="ID" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="MAJORVERSION" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="MINORVERSION" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="PATCHVERSION" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="DATEEXECUTED" type="DATE">
<constraints nullable="false"/>
</column>
<column name="SCRIPT" type="BLOB">
<constraints nullable="false"/>
</column>
<column name="EXECUTIONSTATUS" type="VARCHAR2(200 BYTE)">
<constraints nullable="false"/>
</column>
<column name="REQUESTOR" type="VARCHAR2(400 BYTE)">
<constraints nullable="false"/>
</column>
<column name="LOGREPORT" type="BLOB">
<constraints nullable="false"/>
</column>
<column name="DMLASTUPDATE" type="DATE">
<constraints nullable="false"/>
</column>
<column name="DBAPPLICATIONFK" type="NUMBER(17,0)">
<constraints nullable="false"/>
</column>
<column name="LOGREPORTNAME" type="VARCHAR2(400 BYTE)">
<constraints nullable="false"/>
</column>
<column name="SCRIPTNAME" type="VARCHAR2(400 BYTE)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet author="DELL (generated)" id="1331066972401-6">
<createIndex indexName="SYS_C004087" schemaName="archive_pmd" tableName="PMD00_SEQUENCE" tablespace="SYSTEM" unique="true">
<column name="PMD00_ID"/>
</createIndex>
</changeSet>
<changeSet author="DELL (generated)" id="1331066972401-7">
<createIndex indexName="SYS_C004084" schemaName="archive_pmd" tableName="PMD01_META_DATA" tablespace="SYSTEM" unique="true">
<column name="PMD01_ID"/>
</createIndex>
</changeSet>
<changeSet author="DELL (generated)" id="1331066972401-8">
<createIndex indexName="SYS_C004050" schemaName="archive_pmd" tableName="PMD13_DB_APPLICATION" tablespace="SYSTEM" unique="true">
<column name="ID"/>
</createIndex>
</changeSet>
<changeSet author="DELL (generated)" id="1331066972401-9">
<createIndex indexName="SYS_C004062" schemaName="archive_pmd" tableName="PMD14_DB_VERSION" tablespace="SYSTEM" unique="true">
<column name="ID"/>
</createIndex>
</changeSet>
<changeSet author="DELL (generated)" id="1331066972401-10">
<createIndex indexName="SYS_C004076" schemaName="archive_pmd" tableName="PMD15_DBCOMMIT_LOG" tablespace="SYSTEM" unique="true">
<column name="ID"/>
</createIndex>
</changeSet>
</databaseChangeLog>
=== 这是我的changeLog.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"/>
注意archive_dbs 不包含任何表。为什么liquibase didint 显示archive_pmd 中的表在archive_dbs 中丢失?