Upgrade Laravel constantly and safely
Upgrading framework tends to be put aside because we often prioritize adding new features to products. However, if you don’t upgrade the framework for a long time, upgrading the framework will become a nightmare. Jumping from an old version to the latest version is not only a very tough job but also it’s dangerous due to a large number of changes. In this post, I’ll show you how to upgrade Laravel easily and safely using Laravel Shift.
A big jump is a nightmare
Last year, we upgraded the Lumen 5.1 application to Laravel 5.6 which was a lot of work. First of all, we had to upgrade PHP 5.6 to PHP 7.2 because Laravel didn’t support it any more. After upgrading PHP, we noticed that PHPUnit 4 didn’t support PHP 7 and so we tried to upgrade it, too. However, Lumen 5.1 only supported PHPUnit 4 😨 So, we ended up to upgrade Laravel and PHPUnit at the same time.
After a very tough work, we created a huge pull request with too many changed files. It was almost impossible to review all the changes.
From this experience, I promised myself to upgrade the framework as soon as possible when a newer version is released.
However, one good thing was that we had written a lot of unit and integration tests. Even if something breaks, we could notice before releasing to production.
Laravel Shift is your friend
After upgrading to Laravel 5.6, the version 5.7 came out. This time we upgraded using Laravel Shift which saved a lot of time.
Laravel Shift is a service that scans your Laravel application and automatically creates a pull request for upgrading Laravel. All you have to do is just choose a repository and pay some money. In my case, it costed only $9 but the pricing depends on Laravel version of your application. After one or two minutes, you’ll receive a pull request with very detailed comments like this.
You need to review changed files, check comments from Shift, run
composer update and confirm that all tests pass. Especially, you should carefully check config files that are different from Laravel’s default values.
In my case, it took only a couple of hours to upgrade my Laravel application. It was super easy! I upgraded three applications using Shift. Thank you JMac for creating such a great service!
Laravel Shift is a super useful service but it’s not perfect. It might break some existing functionalities. However, you can notice this before releasing to production and be more confident if you have test code. So, it’s very important to write tests every time you implement a new feature.
Even if you write tests, it’s almost impossible to cover all cases. So, it’s also important to monitor application errors. In my case, I use Sentry for error monitoring. It’s very straightforward to install Sentry to a Laravel application.
When an exception is thrown in the application, Sentry will send you a notification. You can fix the error or roll back the release.
Recently Laravel 5.8 has been released! I’m planning to upgrade after one or two month later because there will be some patch releases for bug fixes.