【发布时间】:2015-03-11 05:01:38
【问题描述】:
当我从命令行运行 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>
它还有很多其他的序列。下一个处理表、索引和视图,与您预期的差不多。
【问题讨论】:
-
您能否提供一个变更日志示例?是包含的变更日志还是根变更日志本身的问题?
-
谢谢@Nathan。当我回到工作岗位时,我会添加更新日志。但简而言之,这就是一切。主要的变更日志只是一系列包含详细信息的内容。但关键是我从命令行获得了相对路径,而从 Ant 获得的是绝对路径。我想使用 Ant,因为在 Liquibase 创建表和其他所有内容之前,我使用它的
<sql>元素来创建实际的架构(或用户,如果它是 Oracle)。 -
@NathanVoxland,我添加了一些变更日志文件。如果您愿意,我可以添加更多细节,或者显示文件结构或其他任何内容。请告诉我。