No more down migrations
Database migrations have had a serious refactor in the newest Tempest release
Read more [tempestphp.com]
Posts tagged with migrations
Database migrations have had a serious refactor in the newest Tempest release
Read more [tempestphp.com]
Every once in a while, someone opens a PR on one of our open source packages adding a down function to the migration. I usually close those PRs fast with a thank you and a message “We don’t use down migrations in our projects”.
While down migrations might seem like a safety net, they're often a false comfort that potentially creates more problems than they solve.
Instead of explaining this in every PR separately, let me share why we don't write down migrations and what we do instead.
Join 9,500+ smart developers
Every month I share what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.
No spam. Unsubscribe anytime. You can also follow me on X.
In this video, Mohammed Said shares a nice, clean strategy for multitenancy in Laravel.
Having a lot of migrations might slow down your tests. My colleague Alex shares how you can fix this.
One of the larger test suites I run daily has about 1500 tests in it. It takes just over 4 minutes to complete at an average of 160ms per test. That's pretty good. However, lately I've noticed a delay between starting PHPUnit and running the first test. This delay grew to the point where running a single test would take almost 12 seconds with the setUp method using most of that time on... migrations.
Read more [alexvanderbist.com]
When the db structure changes, it's sometimes easy to perform the data migration inside a database migration.
— Freek Van der Herten (@freekmurze) February 24, 2018
Migration 1: do the db migration + restructure the data
Migration 2: drop the old columns
I'd only do this for simple stuff. pic.twitter.com/v2roA6OxBc
Read more [twitter.com]
Out of the box Laravel comes with a few commands to migrate the database. One of them is migrate:refresh. That one will first run the down-steps for all your migrations and then run all the up steps. After that process your database should have the same structure as specified in your migrations. But…
Colin Viebrock, author of the well know laravel-sluggable package, created a new Sequel Pro bundle that can genenerate Laravel migration files.
Connect to a database, and select a table in the left-hand column. From the application menu, choose Bundles › Export › Export to Laravel Migration. The resulting Laravel migration file will be saved to your desktop. You can then move this file into your Laravel project (usually /database/migrations) and then run artisan migrate.