views:

398

answers:

3

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

A: 

The "proper" way to do this is a backup before schema change, then rollback in case of error.

You dont say what db you use - but it would wonder me if all schema changes would be supported in transactions. Mos thigh end SQL databases (oracle, db2, sql server) dont do that in all cases for really good reasons. Transacitonal schema changes are REALLY hard and REALLY resouce intensive.

TomTom
Thanks. Using MySQL but I am considering using this for managing some Views in an Oracle 10g as well. Any ideas how to do the backup with Phing then?
Gordon
Nope. Should not be done in there. it is the admins job to make backup before configuration / software changes.
TomTom
Umm, that kinda defeats the purpose of automatic deployment tools like phing, doesn't it?
Gordon
+1  A: 

Why not write a series of undo deltas and add a phing task that runs on failure of the other task?

Steve Robillard
Thanks. I do have undo deltas. But how could I run them automatically? How would the other phing task know how far to run back?
Gordon
in terms of knowing how far back to go you could set a property for the starting point. As for running automatically I am not sure you can do it automatically, but what about setting a task that checks the db versioning table and based on that runs the undo. You may want to look at xinc which has notifiers for success and failure with the ability to run some code logic based on success or failure.
Steve Robillard
A: 

you really should take a look at capistrano. TomTom: you are missing something here: the backup before schema change of course has to be made - but what to do with the NEW data that was inserted meanwhile you were thinking that everything is ok? I do not say, tthat there is a good tool for this problem, but the problem exists in real life.

Aborto Virtuale de la Veritano
Thanks for the suggestion. I'd like to stay in the PHP ecosystem if possible though.
Gordon