Phing部署因数据库迁移而失败

时间:2013-09-06 06:11:43

标签: svn deployment zend-framework2 phing

我正在尝试使用 Phing 来部署我的项目。 Checkout from SVNRunning Composer脚本运行良好,但我的数据库迁移却没有。这是错误消息:

  

执行目标“迁移”失败的原因如下:任务退出代码2
  sh:无法打开build / scripts / deploy-.sql:没有这样的文件

似乎Phing不会生成增量文件。

我的Migration脚本如下所示:

<target name="migration" description="Datenbankmigration">
  <property file="${phing.dir}/includes/build.properties"/>
  <propertyprompt propertyName="db.name" defaultValue="${db.name}" promptText="Datenbankname angeben falls nicht der Defaultwert genutzt werden soll. Default:" />
  <propertyprompt propertyName="db.username" defaultValue="${db.username}" promptText="Datenbankbenutzernamen angeben falls nicht der Defaultwert genutzt werden soll. Default:" />
  <propertyprompt propertyName="db.password" defaultValue="" promptText="Datenbankpasswort angeben falls nicht der Defaultwert genutzt werden soll. Default:" />
  <propertyprompt propertyName="db.host" defaultValue="${db.host}" promptText="Host angeben falls nicht der Defaultwert genutzt werden soll. Default:" />

  <!-- load the dbdeploy task -->
  <taskdef name="dbdeploy" classname="phing.tasks.ext.dbdeploy.DbDeployTask" />

  <!-- these two filenames will contain the generated SQL to do the deploy and roll it back -->
  <property name="build.dbdeploy.deployfile" value="${phing.dir}build/scripts/deploy-${DSTAMP}${TSTAMP}.sql" />
  <property name="build.dbdeploy.undofile" value="${build.dir}build/scripts/undo-${DSTAMP}${TSTAMP}.sql" />

  <!-- create the changelog Table -->
  <pdosqlexec url="mysql:host=${db.host};dbname=${db.name}" userid="${db.username}" password="${db.password}">
    <transaction src="build/sql/changelog.sql"/>
  </pdosqlexec>

  <!-- generate the deployment scripts -->
  <dbdeploy
    url="mysql:host=${db.host};dbname=${db.name}"
    userid="${db.username}"
    password="${db.password}"
    dir="${phing.dir}/sql/delta"
    outputfile="${build.dbdeploy.deployfile}"
    undooutputfile="${build.dbdeploy.undofile}" />

  <!-- execute the SQL - Use mysql command line to avoid trouble with large
  files or many statements and PDO -->
  <exec
    command="mysql -h${db.host} -u${db.username} -p${db.password} ${db.name} &lt; ${build.dbdeploy.deployfile}"
    dir="${phing.dir}"
    checkreturn="true"
    output="${phing.dir}/cache/deploy-${DSTAMP}${TSTAMP}.log"
    error="${phing.dir}/cache/deploy-error-${DSTAMP}${TSTAMP}.log"
  />

  <echo msg="Datenbank erfolgreich angelegt"/>

</target>

有谁知道为什么?

1 个答案:

答案 0 :(得分:1)

首先,您似乎忘记了目标中的<tstamp />标记,以便${DSTAMP}${TSTAMP}变量有效。

然后你应该像这样定义你的属性:

<property name="build.dbdeploy.deployfile" value="deploy-${DSTAMP}${TSTAMP}.sql" />
<property name="build.dbdeploy.undofile" value="undo-${DSTAMP}${TSTAMP}.sql" />

它们应自动放在您在dir参数中指定的目录中。