Introducing Laravel Migration
Pulling legacy data into a fresh Laravel app is a recurring problem across the projects I work on, and every time I'd reach for the same patterns: chunked reads, idempotent writes, traceable progress. laravel-migration bundles those patterns into a small set of commands.
What it does
- Scaffold migration job classes with
php artisan migration:new-job {JobName}. - Run a single migration synchronously while iterating:
php artisan migration:run {OldTableName}. - Run the full set in dependency order:
php artisan migration:run --all. - Handle scale — from 100 rows to millions — with chunked, queueable jobs.
Why a package instead of one-off scripts
Creating this package allowed me to implement a core migration functionality once which I can be confident to use in future projects. Through development on projects the package has become fairly battle tested, and is going to be my go to solution for implementing database migrations.
Example: a typical handleItem
public function handleItem($item): void
{
$data = [
'first_name' => $item->FNAME,
'last_name' => $item->LNAME,
'email' => $item->EMAIL_ADDR,
'updated_at' => $item->EDTIME ? Carbon::parse($item->EDTIME) : now(),
];
$record = new User();
$record->fill($data);
$record->saveQuietly();
}
Installation
The package lives at paper-leaf-tech/laravel-migration. Add the repository to your composer.json and require it:
"repositories": [
{
"type": "github",
"url": "[email protected]:paper-leaf-tech/laravel-migration.git"
}
]
composer require paper-leaf-tech/laravel-migration
php artisan laravel-migration:install
Memory considerations
The chunked job design is intended to be conservative on both memory, as well as php execution time limits. You can modify the chunk size such that handleItem will process a limited count of items to satisfy memory limits.