Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Phing's dbdeploy task to automatically rollback on delta error

I am using Phing's dbdeploy task to manage my database schema. This is working fine, as long as there is no errors in the queries of my delta files.

However, if there is an error, dbdeploy will just run the delta files up to the query with the error and then abort. This causes me some frustration, because I have to manually rollback the entry in the changelog table then. If I don't, dbdeploy will assume the migration was successful on a subsequent try, so any retries will do nothing.

So the question is, is there any way to get dbdeploy use transactions or can you suggest any other way to have phing rollback automatically when an error occurs?

Note: I'm not that proficient with Phing, so if this involves writing a custom task, any example code or a url with further information is highly appreciated. Thanks

like image 792
Gordon Avatar asked Mar 16 '10 11:03

Gordon


1 Answers

(if you're still out there...) Regarding phing for a db dump task, use the db's dump utility and create a phing task. I use postgres mainly and have this in my phing build.xml:

<target name="db-dump" depends="">
    <php expression="date('Ymd-Hi')" returnProperty="phing.dump.ts"/>
    <exec command="pg_dump -h ${db.host} -U ${db.user} -O ${db.name} | gzip > ${db.dumppath}/${db.name}-${phing.dump.ts}.gz" />
</target>
like image 99
Foot Avatar answered Sep 21 '22 11:09

Foot