A Laravel package for running one-time data migration and transformation jobs in a controlled way.
It lets you define Artisan commands as data jobs that run once by default, can be prioritized, and are fully tracked. This is useful for tasks like migrating data after schema changes or backfilling data for new features.
The package automatically discovers these jobs, runs them in priority order, and records their status as pending, running, completed, or failed in the database. A single Artisan command, data:run-jobs, handles executing all registered jobs safely and in order.
When working on Laravel applications, you often need to run one-time data migrations or transformations—tasks that don't fit into regular database migrations but still need to be executed in a controlled, trackable way. These might include:
Managing these tasks manually is error-prone and makes it difficult to track what has been executed across different environments.
Laravel Data Jobs provides a simple, elegant solution by turning Artisan commands into trackable, priority-based data jobs. Simply add the DataJobable trait to your command, and the package handles:
Install the package via Composer:
composer require badrshs/laravel-data-jobs
Run the installation command:
php artisan data-jobs:install
This will:
config/data-jobs.phpdata_jobs_log tableCreate a new Artisan command:
php artisan make:command MigrateUsersCommandExample
Add the DataJobable trait to your command and optionally customize priority:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Badrshs\LaravelDataJobs\Contracts\DataJobable;
class MigrateUsersCommandExample extends Command
{
use DataJobable;
protected $signature = 'data:migrate-users';
protected $description = 'Migrate users to new structure';
// Optional: Set job priority (lower numbers run first, default: 100)
public function getJobPriority(): int
{
return 10;
}
// Optional: Define job metadata/parameters
public function getJobParameters(): array
{
return ['batch' => 'user-migration'];
}
// Optional: Disable this job so it gets skipped during execution (default: true)
public function isEnabled(): bool
{
return false;
}
public function handle(): int
{
$this->info('Migrating users...');
// Your migration logic here
$this->info('Migration complete!');
return self::SUCCESS;
}
}
Execute all pending jobs:
php artisan data:run-jobs
The package will automatically discover and execute all commands using the DataJobable trait, sorted by priority.
Run a specific job:
php artisan data:run-jobs --job=MigrateUsersCommandExample
Force re-run completed jobs:
php artisan data:run-jobs --force
Clear all logs and run fresh:
php artisan data:run-jobs --fresh
DataJobable traitisEnabled(): false) are filtered out immediately with a 🚫 Disabled messagedata_jobs_log tablePublish and customize the configuration file:
php artisan vendor:publish --tag=data-jobs-config
Available options in config/data-jobs.php:
return [
// Database table name for job logs
'log_table' => 'data_jobs_log',
// Enable/disable execution logging (jobs run without DB tracking when false)
'logging_enabled' => true,
// Auto-run pending jobs (not yet implemented)
'auto_run' => false,
];
When running jobs, you'll see clear progress feedback:
🚀 Starting data jobs execution...
┌──────────┬──────────────────────────────┬───────────┐
│ Priority │ Job Class │ Status │
├──────────┼──────────────────────────────┼───────────┤
│ 10 │ MigrateUsersCommandExample │ pending │
│ 20 │ UpdateStatsCommandExample │ completed │
└──────────┴──────────────────────────────┴───────────┘
🚫 Disabled: DisabledJobExample (skipped)
▶️ Running: MigrateUsersCommandExample
✅ Completed: MigrateUsersCommandExample
⏭️ Skipping UpdateStatsCommandExample (already completed)
📊 Execution Summary:
- Executed: 1
- Skipped: 1
- Failed: 0
Run the test suite:
vendor/bin/phpunit
Or using Composer:
composer test
Contributions are welcome! Please see CONTRIBUTING.md for details.
The MIT License (MIT). Please see License File for more information.
How can I help you explore Laravel packages today?