我是第一次测试Flyway,版本2.1.1。
我正在使用Ant任务migrate
,它应该创建schema_version
表(如果它尚不存在(并且它在我的模式中不存在),并且我收到此错误:
C:\Users\dmusiani\Desktop\flyaway-test>ant
Buildfile: build.xml
migrate-db:
[flyway:migrate] com.googlecode.flyway.core.api.FlywayException: Found non-empty
schema "SYSTEM" without metadata table! Use init() first to initialize the meta
data table.
BUILD FAILED
C:\Users\dmusiani\Desktop\flyaway-test\build.xml:37: Flyway Error: com.googlecod
e.flyway.core.api.FlywayException: Found non-empty schema "SYSTEM" without metad
ata table! Use init() first to initialize the metadata table.
Total time: 0 seconds
C:\Users\dmusiani\Desktop\flyaway-test>
我尝试在迁移之前添加init
,并且第一次全部工作,但是当我第二次启动构建时,我从init
说明表中已经存在错误
这是我的Ant目标:
<target name="migrate-db">
<path id="flyway.lib.path">
<fileset dir="./lib">
<include name="**/flyway*.jar"/>
</fileset>
</path>
<path id="flyway.classpath">
<fileset dir="./lib" includes="ojdbc6-11.2.0.3.jar"/>
</path>
<taskdef uri="antlib:com.googlecode.flyway.ant"
resource="com/googlecode/flyway/ant/antlib.xml"
classpathref="flyway.lib.path"/>
<flyway:init driver="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:WBMD"
user="system"
password="manager"
initVersion="0"
initDescription="Version table initialization (table "USERNAME"."schema_version" )"/>
<flyway:migrate driver="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:WBMD"
user="system"
password="manager"
sqlMigrationPrefix="patch" >
<locations>
<location path="integrations-runtime/HELIOS/1-9-0/nlip-0-5-0/migration/system"/>
</locations>
</flyway:migrate>
</target>
有关如何修复它的任何建议吗?
答案 0 :(得分:1)
在等待2.2时,我已成功测试(到oracle DB)以下“自动”方式来初始化Flyway元数据表:
<target name="flyway.init.check">
<!-- Select on the DB to see if the metadata table is already in place-->
<sql driver="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:WBMD"
userid="user"
password="pwd"
print="yes"
output="temp.properties"
expandProperties="true"
showheaders="false"
showtrailers="false"
classpathref="flyway.classpath">
<![CDATA[
select 'flyway.metadata.initialized=true' from user_tables where table_name = 'schema_version';
]]>
</sql>
<!-- load as properies the output from the select -->
<property file="temp.properties" />
<delete file="temp.properties" quiet="true"/>
</target>
<target name="flyway.init" depends="flyway.init.check" unless="flyway.metadata.initialized">
<flyway:init driver="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:WBMD"
user="user"
password="pwd"
initVersion="0"
initDescription="Version table initialization"/>
</target>
<target name="migrate-db" depends="flyway.init">
......
</target>
如果你愿意,可以享受(也许使用ant-contrib,你可以获得更简单,更紧凑的解决方案)
的Davide
答案 1 :(得分:0)
你必须为Flyway初始化一次db。这就是Flyway创建用于跟踪迁移的表格。正如您所注意到的,任何尝试再次尝试都会失败,因为该表已经存在。
我建议创建一个单独的ant任务,调用Flyway's init,你可以手动运行来初始化Flyway,这有点像:
<target name="init-flyway">
<path id="flyway.lib.path">
<fileset dir="./lib">
<include name="**/flyway*.jar"/>
</fileset>
</path>
<path id="flyway.classpath">
<fileset dir="./lib" includes="ojdbc6-11.2.0.3.jar"/>
</path>
<taskdef uri="antlib:com.googlecode.flyway.ant"
resource="com/googlecode/flyway/ant/antlib.xml"
classpathref="flyway.lib.path"/>
<flyway:init driver="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:WBMD"
user="system"
password="manager"
initVersion="0"
initDescription="Version table initialization (table "USERNAME"."schema_version" )"/>
</target>