Do we still need Down migrations? Taylor says No.

On the last episode of Laravel Podcast, Taylor Otwell said something controversial but I had a gut feeling about it for a long time. So, do you actually use down() method in migrations, and rollback them? In fact, there are two problems. First, that people don't actually test down migrations. Developers tend to think only forward, feeling excitement to create new project but often forgetting about rollbacks. It's like some people have a backup of the database but never actually tried to perform a restore from that backup (remember GitLab story?). So I've seen quite a few projects where developers write down() migrations but never actually care about whether they work. * * * * * Problem no.2 is a question - do we actually need Down migrations? Are those rollbacks the right way to fix some screw up? This is what Taylor said about it.
My view on that recently, in a past year, has been that you just never rollback. Ever. You would always go forward. Because I don't know how you roll back without losing customer data. At least for my own projects like Forge or Envoyer, I could never really guarantee that I wasn't losing data, so I think if at all possible, what I would try to do is write an entirely new migration that fixes whatever problem there is, and it would just migrate forward. Sometimes, if it's low traffic, and you feel pretty certain that no one's messed with the new database schema, then probably you could just roll back, but.. I've actually stopped writing down() methods in my migrations entirely, recently, now that it's optional. But it's really mainly feasible in Laravel 5.5, cause you have the new db:fresh method which just totally drops all tables without running down methods.
So, if Laravel creator himself doesn't use it, why should we? You can also listen to the thoughts on migrations and rollbacks by Matt and Jeffrey on the original podcast from 30:18 minute. Off-topic: by the way, do you know any other active Taylor in Laravel community? I keep mentioning full name, sometimes with link to Twitter, but I think we're at the point where I just say Taylor and everyone know who am I talking about? :)

No comments yet…

Like our articles?

Become a Premium Member for $129/year or $29/month

Written by

You might also like