I added transactional support to the Yii Migrate Command in 1.1.6. The up and down function are wrapped in individual transactions. If your migration fails, then the transaction will be rolled back and your database will be left in it’s original state.
I’ve attached a patch file of the changes required.
I agree that it is a good idea (even essential) to support transactions in migrations.
Thanks for the patch, however where you positioned the transaction statements means that if multiple migrations are being chained and one fails, the application will continue with the others (after having rolled back the one that failed). This may be a matter of opinion, but I think that if one fails then the whole operation should roll back, allowing you to apply individual migrations if desired.
To this end, here is my extension to do that. The code is nothing great, since there is not much you can do without modifying the original code, so it would be good if something was done in the core.
However, just to put a dampener on it, it would appear that due to a bug in MySQL, transactions are automatically committed for operations such as creating and dropping tables (PHP PDO), so if we have a migration that creates multiple tables (or something similar) that then fails, our rollback will not be effective
Still, it can still be useful for other operations - I think we just need to remember to keep these operations separate from other operations in our migrations.