mshkop / laravel-data-migrations
Data migrations for Laravel, kept apart from schema migrations (own table, folder and artisan commands). Maintained fork of jlorente/laravel-data-migrations.
Requires
- php: ^8.2
- illuminate/console: ^12.0 || ^13.0
- illuminate/database: ^12.0 || ^13.0
- illuminate/support: ^12.0 || ^13.0
Requires (Dev)
- orchestra/testbench: ^10.0 || ^11.0
- phpunit/phpunit: ^11.0 || ^12.0
Suggests
None
Provides
None
Conflicts
Replaces
None
README
Data migrations for Laravel, kept apart from schema migrations: their own folder (database/migrations_data),
their own table and their own artisan commands. Use them for one-off data changes (backfills, settings,
permissions, seed-like updates) that must run once per environment, in order, on deploy.
Maintained fork of jlorente/laravel-data-migrations (MIT, by José Lorente), updated for Laravel 12 and 13.
Requirements
- PHP 8.2+
- Laravel 12 or 13
Installation
composer require mshkop/laravel-data-migrations
The service provider is auto-discovered. Publish the config and the migrations folder:
php artisan vendor:publish --tag=data-migrations
Configuration
config/data-migrations.php:
return [ // table of the executed data migrations - never the same as the schema "migrations" table 'table' => 'migrations_data', ];
Usage
| Command | What it does |
|---|---|
php artisan make:data-migration <name> |
create a data migration in database/migrations_data |
php artisan migrate-data |
run the pending data migrations |
php artisan migrate-data:rollback |
roll back the last batch |
php artisan migrate-data:install |
create the data migrations table (done automatically by migrate-data) |
A data migration is a normal Laravel migration class:
use App\Models\Setting; use Illuminate\Database\Migrations\Migration; return new class extends Migration { public function up(): void { Setting::query()->updateOrCreate(['key' => 'feature.enabled'], ['value' => true]); } public function down(): void { Setting::query()->where('key', 'feature.enabled')->delete(); } };
The commands take every option of their framework counterparts (migrate, migrate:rollback,
migrate:install, make:migration) of the installed Laravel version: --force, --pretend, --step,
--database, --path, --graceful, ... A --path is relative to the project root.
Typical deploy order: php artisan migrate --force then php artisan migrate-data --force.
Migrating from jlorente/laravel-data-migrations
composer remove jlorente/laravel-data-migrations && composer require mshkop/laravel-data-migrations- Replace references to the
Jlorente\DataMigrations\namespace, if you have any (an explicitly registered service provider, subclasses of its commands). - Keep your
config/data-migrations.php: the table, the folder and the command names are the same, so the already executed data migrations are not run again.
Changes compared to jlorente/laravel-data-migrations 2.0.2
- Laravel 13 support. The original commands hardcoded copies of the framework command signatures, so
migrate-datafailed withThe "schema-only" option does not exist, andmigrate-data:installregistered itself asmigrate:install, replacing the schema command. The commands now derive their definition from the installed framework command and only change the name. migrate-datano longer tries to load a schema dump.- Config defaults are merged, so the published config file is optional.
- Tests (Orchestra Testbench) and CI.
Testing
composer install
composer test
License
MIT - see LICENSE.txt.