Liquibase 从 Ant 和命令行给出不同的结果
Liquibase gives different results from Ant and the command line
当我从命令行 运行 Liquibase 时,它会使用更新日志文件的相对路径填充 DATABASECHANGELOG
的 FILENAME
列,正如您所希望的那样。但是当我 运行 来自完全相同目录的完全相同的更新日志时,使用 Ant,它会用绝对路径填充该列。
除其他外,这意味着 Ant 和命令行版本对我来说不可互操作。
但是我找不到其他人报告过这个问题,所以我确定这是我正在做的事情;我没有正确设置的东西。我看到一些建议说更改日志的根目录需要在类路径中,所以我将它包含在 Ant 类路径中,但这没有任何区别。
这是我的 Ant 构建文件:
<project name="Database Build" default="build" basedir="." xmlns:liquibase="antlib:liquibase.integration.ant">
<path id="liquibase.lib.path">
<fileset dir="liquibase/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="liquibase">
<include name="liquibase.jar" />
</fileset>
</path>
<path id="driver.classpath">
<filelist files="${classpath}" />
</path>
<path id="main.classpath">
<pathelement location="." />
<path refid="driver.classpath" />
</path>
<taskdef
resource="liquibase/integration/ant/antlib.xml"
uri="antlib:liquibase.integration.ant">
<classpath refid="liquibase.lib.path" />
</taskdef>
<liquibase:database
id="main-schema"
driver="${driver}"
url="${url}"
user="${username}"
password="${password}"
defaultSchemaName="${defaultSchemaName}"
/>
<target
name="build"
description="Builds the database based on values set in the properties file">
<echo message="Building DB..." />
<liquibase:updateDatabase
databaseref="main-schema"
changelogfile="${changeLogFile}"
classpathref="main.classpath"
logLevel="debug"
>
<!-- Here we're effectively passing the values set as Ant properties in as Liquibase parameters -->
<liquibase:changeLogParameters>
<liquibase:changeLogParameter name="main.schema" value="${defaultSchemaName}" />
<liquibase:changeLogParameter name="tablespace.data" value="${tablespace.data}" />
<liquibase:changeLogParameter name="tablespace.index" value="${tablespace.index}" />
<liquibase:changeLogParameter name="tablespace.long" value="${tablespace.long}" />
</liquibase:changeLogParameters>
</liquibase:updateDatabase>
</target>
<target
name="createSchema"
description="Create a schema on the database"
>
<echo>${toString:main.classpath}</echo>
<sql
driver="${driver}"
classpathref="main.classpath"
url="${url}"
userid="${username}"
password="${password}"
expandProperties="true"
>
<transaction>
CREATE SCHEMA ${defaultSchemaName};
</transaction>
</sql>
</target>
<target
name="createOracleUsers"
description="Create a user in Oracle"
>
<sql
rdbms="oracle"
print="true"
driver="${driver}"
classpathref="main.classpath"
url="${url}"
userid="${username}"
password="${password}"
expandProperties="true"
>
<transaction>
CREATE USER ${defaultSchemaName} IDENTIFIED BY ${defaultSchemaName}
default tablespace ${tablespace.data}
temporary tablespace TEMP quota unlimited on ${tablespace.data}
quota unlimited on ${tablespace.index};
GRANT create session, alter session, create sequence,
create table, create view to ${defaultSchemaName};
</transaction>
</sql>
</target>
</project>
编辑以添加一些更新日志文件。
这是根更改日志文件:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
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-3.3.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<include file="changes/sequences/sequences.xml" relativeToChangelogFile="true" />
<include file="changes/baseobjects/db-511.xml" relativeToChangelogFile="true" />
<include file="changes/data/data-511.xml" relativeToChangelogFile="true" />
</databaseChangeLog>
包含的第一个开始是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
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-3.3.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet dbms="oracle,db2,db2i" author="mccallim (generated)" id="1419011907193-1">
<createSequence schemaName="${main.schema}" cacheSize="100" cycle="false" incrementBy="1" minValue="1" sequenceName="SEQ_ALLOWEDCURRENCIES" startValue="1"/>
</changeSet>
...
</databaseChangeLog>
它还有很多其他序列。下一个处理表、索引和视图,与您预期的差不多。
它看起来像一个错误。我创建了 https://liquibase.jira.com/browse/CORE-2290 来跟踪 3.3.3
的修复
当我从命令行 运行 Liquibase 时,它会使用更新日志文件的相对路径填充 DATABASECHANGELOG
的 FILENAME
列,正如您所希望的那样。但是当我 运行 来自完全相同目录的完全相同的更新日志时,使用 Ant,它会用绝对路径填充该列。
除其他外,这意味着 Ant 和命令行版本对我来说不可互操作。
但是我找不到其他人报告过这个问题,所以我确定这是我正在做的事情;我没有正确设置的东西。我看到一些建议说更改日志的根目录需要在类路径中,所以我将它包含在 Ant 类路径中,但这没有任何区别。
这是我的 Ant 构建文件:
<project name="Database Build" default="build" basedir="." xmlns:liquibase="antlib:liquibase.integration.ant">
<path id="liquibase.lib.path">
<fileset dir="liquibase/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="liquibase">
<include name="liquibase.jar" />
</fileset>
</path>
<path id="driver.classpath">
<filelist files="${classpath}" />
</path>
<path id="main.classpath">
<pathelement location="." />
<path refid="driver.classpath" />
</path>
<taskdef
resource="liquibase/integration/ant/antlib.xml"
uri="antlib:liquibase.integration.ant">
<classpath refid="liquibase.lib.path" />
</taskdef>
<liquibase:database
id="main-schema"
driver="${driver}"
url="${url}"
user="${username}"
password="${password}"
defaultSchemaName="${defaultSchemaName}"
/>
<target
name="build"
description="Builds the database based on values set in the properties file">
<echo message="Building DB..." />
<liquibase:updateDatabase
databaseref="main-schema"
changelogfile="${changeLogFile}"
classpathref="main.classpath"
logLevel="debug"
>
<!-- Here we're effectively passing the values set as Ant properties in as Liquibase parameters -->
<liquibase:changeLogParameters>
<liquibase:changeLogParameter name="main.schema" value="${defaultSchemaName}" />
<liquibase:changeLogParameter name="tablespace.data" value="${tablespace.data}" />
<liquibase:changeLogParameter name="tablespace.index" value="${tablespace.index}" />
<liquibase:changeLogParameter name="tablespace.long" value="${tablespace.long}" />
</liquibase:changeLogParameters>
</liquibase:updateDatabase>
</target>
<target
name="createSchema"
description="Create a schema on the database"
>
<echo>${toString:main.classpath}</echo>
<sql
driver="${driver}"
classpathref="main.classpath"
url="${url}"
userid="${username}"
password="${password}"
expandProperties="true"
>
<transaction>
CREATE SCHEMA ${defaultSchemaName};
</transaction>
</sql>
</target>
<target
name="createOracleUsers"
description="Create a user in Oracle"
>
<sql
rdbms="oracle"
print="true"
driver="${driver}"
classpathref="main.classpath"
url="${url}"
userid="${username}"
password="${password}"
expandProperties="true"
>
<transaction>
CREATE USER ${defaultSchemaName} IDENTIFIED BY ${defaultSchemaName}
default tablespace ${tablespace.data}
temporary tablespace TEMP quota unlimited on ${tablespace.data}
quota unlimited on ${tablespace.index};
GRANT create session, alter session, create sequence,
create table, create view to ${defaultSchemaName};
</transaction>
</sql>
</target>
</project>
编辑以添加一些更新日志文件。
这是根更改日志文件:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
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-3.3.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<include file="changes/sequences/sequences.xml" relativeToChangelogFile="true" />
<include file="changes/baseobjects/db-511.xml" relativeToChangelogFile="true" />
<include file="changes/data/data-511.xml" relativeToChangelogFile="true" />
</databaseChangeLog>
包含的第一个开始是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
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-3.3.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet dbms="oracle,db2,db2i" author="mccallim (generated)" id="1419011907193-1">
<createSequence schemaName="${main.schema}" cacheSize="100" cycle="false" incrementBy="1" minValue="1" sequenceName="SEQ_ALLOWEDCURRENCIES" startValue="1"/>
</changeSet>
...
</databaseChangeLog>
它还有很多其他序列。下一个处理表、索引和视图,与您预期的差不多。
它看起来像一个错误。我创建了 https://liquibase.jira.com/browse/CORE-2290 来跟踪 3.3.3
的修复