Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Migrations - Am I doing it wrong, or could migrations be improved?
Here is an example of a migration I wrote.
Every migration I write shares a lot of code to try to make them more stable and more verbose. For each method (up/down), it attempts the migration using transactions in a try/catch block, so if it fails it rolls back the transaction and outputs which direction the migration failed and the exception message. The only way I could get the migration to prevent the next migration from running on failure is to put an exit in the catch. I'm not sure if an improved/different Migrations system is going to be considered for the next version of FuelPHP, if so can you consider the feedback above?
First the answer to the question (as given on IRC) is to rethrow the exception after handling it, don't exit as Fuel can't continue it's execution in those cases. But to the other points: We can't add that by default as it won't work for everyone, and not everyone uses migrations just for Query-Builder compatible stuff (what if they're using Doctrine? Or a non-SQL compatible DB?). Also important is that transactions often have limitations, like not being able to rollback a table creation - that least to an auto-commit once it's done. And thus the rollback isn't entirely trustworthy either, something we would suggest by implementing it like that. This is one of those cases where it is really important people understand what they are doing, just because of the differences between implementations and limitations of each of those. If you want the transactions and try-catch block in each migration anyway you can create your own Migration base class that takes care of this for you. There are changes to migrations in store for 2.0 but as you'll understand from the above comments there won't be anything making the migrations dependant upon the availability of transaction functionality in your DB backend.
Add a Comment
It looks like you're new here. If you want to get involved, click one of these buttons!
Apply for Membership
↳ Job Board
↳ Installation & Setup
↳ Tips and Tutorials
↳ Code share
In this Discussion