I'd like to do something like the following in my Phing build.xml:
<if>
<not>
<dbexists dsn="mysql:host=${database.host}" username="${database.username}" password="${database.password}" database="${database.name}"/>
</not>
<then>
<pdosqlexec url="mysql:host=${database.host}" userid="${database.username}" password="${database.password}">
CREATE DATABASE ${database.name};
</pdosqlexec>
<pdosqlexec url="mysql:host=${database.host};dbname=${database.name}" userid="${database.username}" password="${database.password}">
<transaction src="create-database-schema.sql"/>
</pdosqlexec>
</then>
</if>
Unfortunately I can't think of any way that this would be possible. A dbexists task obviously doesn't exist and it's impossible to create a custom condition.
The only remaining possibility is to create a custom task which (in PHP) checks for the existence of the database and returns 'Yes' or 'No', which can be assigned into a property and used in a Phing condition. Problem is, I don't know if that's even possible; I can't see anything in the documentation about assigning a property from within a custom task and Google isn't helping either.
Does anyone have any ideas?