I am trying to use Phing to deploy my project. The Checkout from SVN
and Running Composer
scripts work great but the migration for my database doesn't. Here's the error message:
Execution of target "migration" failed for the following reason: Task exited with code 2
sh: cannot open build/scripts/deploy-.sql: No such file
It seems that the delta file is not generated by Phing.
My Migration
script looks like this:
<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} < ${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>
Does anyone have any idea why?
First, it seems like you forgot the <tstamp />
tag in your target so that the ${DSTAMP}
and ${TSTAMP}
variables work.
Then you should define your properties like this :
<property name="build.dbdeploy.deployfile" value="deploy-${DSTAMP}${TSTAMP}.sql" />
<property name="build.dbdeploy.undofile" value="undo-${DSTAMP}${TSTAMP}.sql" />
They should be automatically placed in the directory you specified in the dir
argument.