Search by

lacodix / laravel-data-migrations

lacodix

An extension to allow you to separate data migrations from structure migrations

Package info

github.com/lacodix/laravel-data-migrations

pkg:composer/lacodix/laravel-data-migrations

Statistics

Installs: 362

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v3.1.0 2026-11-28 18:59 UTC

README

Latest Version on Packagist Total Downloads License

Keep changes to existing data separate from schema migrations. Laravel's migrate commands continue to use database/migrations and the migrations history table. This package uses database/migrations_data and a separate migrations_data history table.

This is a fork of jlorente/laravel-data-migrations, originally authored by José Lorente Martín. Lacodix has taken over ongoing maintenance and development. Original author and MIT attribution are preserved.

Lacodix LaravelDataMigrations 3.x is a breaking package and namespace change: the Composer package is lacodix/laravel-data-migrations, and the public namespace changes from Jlorente\DataMigrations to Lacodix\LaravelDataMigrations. Existing consumers must replace the upstream dependency and update imports and manual provider/class references; see Upgrade from jlorente 2.x.

Lacodix LaravelDataMigrations 3.x uses the Lacodix\LaravelDataMigrations namespace. Release 3.1 supports Laravel 12 and 13; the compatibility table shows which release fits your Laravel version.

Compatibility

Laravel PHP Package release
13.44 and newer 8.3+ lacodix/laravel-data-migrations 3.1 or newer
13.0 – 13.43 8.3+ lacodix/laravel-data-migrations 3.0 or 3.1
12 8.2+ lacodix/laravel-data-migrations 3.0 or 3.1
11 8.2+ lacodix/laravel-data-migrations 3.0.x; 3.1 requires Laravel 12 or newer
10 and older as your Laravel version requires jlorente/laravel-data-migrations 2.x (declares Laravel 8 and newer), or 1.x (declares Laravel 5.5 – 7)

3.0 declares support for every Laravel 13 release but fails on Laravel 13.44 and newer: migrate-data stops with The "schema-only" option does not exist before it runs a migration. Use 3.1 there, see Upgrade from 3.0 to 3.1. 3.1 drops Laravel 11; Laravel 11 installations stay on 3.0.x, which keeps working there. For Laravel 10 and older, use the upstream package this one is forked from.

CI for 3.1 tests stable and lowest installable dependencies on PHP 8.2 – 8.5 with Laravel 12 and on PHP 8.3 – 8.6 with Laravel 13. PHP 8.6 is not part of the Laravel 12 lanes.

Installation and configuration

composer require lacodix/laravel-data-migrations:^3.0
php artisan vendor:publish --tag=data-migrations

Laravel discovers Lacodix\LaravelDataMigrations\DataMigrationsServiceProvider automatically. If you disable discovery, add that provider to your application's bootstrap/providers.php list.

Publication creates config/data-migrations.php and the default migration directory. The default table is also available without publishing the configuration. To customize it, edit the published file:

<?php

return [
    'table' => 'migrations_data',
];

Choose a table name different from Laravel's schema migration history table. Existing application settings take precedence over the package default.

Create, run and roll back

php artisan make:data-migration insert_example_setting
php artisan migrate-data
php artisan migrate-data:rollback

The maker creates a migration file only. migrate-data creates its tracking table when needed, then runs pending data migrations. migrate-data:install creates just the tracking table and accepts --database.

Run your schema migrations first so the tables used by your data migrations already exist. For example, given an example_settings table with key and value string columns and a unique key, a data migration could contain:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    public function up(): void
    {
        DB::table('example_settings')->insert([
            'key' => 'timezone',
            'value' => 'UTC',
        ]);
    }

    public function down(): void
    {
        DB::table('example_settings')->where('key', 'timezone')->delete();
    }
};

The filename and batch are recorded in migrations_data. Running migrate-data again skips recorded files; rollback calls down() and removes the corresponding history rows. Schema history remains independent. Write reversible migrations suited to your own data: this example assumes it owns the inserted setting.

Use relative paths for the maker. Run and rollback also support arrays of paths and absolute paths with --realpath:

php artisan make:data-migration insert_example_setting --path=database/custom_data
php artisan migrate-data --path=database/custom_data --database=sqlite --step
php artisan migrate-data:rollback --path=database/custom_data --database=sqlite --step=1
php artisan migrate-data --path=/absolute/path/to/data_migrations --realpath
php artisan migrate-data:rollback --path=/absolute/path/to/data_migrations --realpath

make:data-migration retains the upstream limitation that its --realpath flag does not change path resolution: its --path is relative to the application root. Use a relative maker path even though the flag appears in help. --create and --table use Laravel's migration stubs; avoid putting schema changes in data migrations. The inherited --fullpath option is deprecated in modern Laravel; output formatting follows the installed framework.

migrate-data and rollback accept --pretend; no migration changes are applied, but a first run can still create the tracking table. --step on run gives each migration its own batch; on rollback it limits the number rolled back. In production, commands require confirmation or --force. --graceful on run returns success even if a migration throws, so inspect the output and migration history before treating it as complete. --isolated on run skips the run while another instance of the command holds Laravel's command-isolation lock; it needs a cache store shared by all servers.

migrate-data is a standalone command and does not extend Laravel's migrate command, so options added to migrate for schema work can neither reach it nor break it. Its complete option set is --database, --force, --path, --realpath, --pretend, --step, --graceful and --isolated. Schema and seeding options such as --seed, --seeder, --schema-path and --schema-only do not apply to data migrations and are rejected as unknown options; run php artisan db:seed separately. migrate-data:install, migrate-data:rollback and make:data-migration still extend their Laravel counterparts.

Use php artisan help migrate-data and php artisan help migrate-data:rollback for the available options; the rollback options follow your framework version. There are no data-specific reset, fresh or status commands. Laravel's schema rollback does not roll back data history; plan deployment and rollback order explicitly.

Upgrade from 3.0 to 3.1

3.1 requires Laravel 12 or 13. Laravel 13.44 added a --schema-only option to its migrate command. migrate-data in 3.0 inherited Laravel's handler but declared its own options, so on Laravel 13.44 and newer every call failed with The "schema-only" option does not exist before a migration ran.

In 3.1, migrate-data no longer extends Laravel's migrate command. It has its own handler and keeps the options --database, --force, --path, --realpath, --pretend, --step, --graceful and --isolated. --seed is removed. In 3.0 it ended with The "seeder" option does not exist after the migrations had run, because Laravel's handler reads a --seeder option that the data command never declared. Use php artisan db:seed separately. Migration files, the history table and the other commands are unchanged.

Upgrade from jlorente 2.x

You must remove jlorente/laravel-data-migrations and install lacodix/laravel-data-migrations:^3.0, rather than adding both packages. The package has no legacy namespace aliases or Composer replace declaration for upstream.

Identifier Upstream 2.x Lacodix LaravelDataMigrations 3.x
Composer package jlorente/laravel-data-migrations lacodix/laravel-data-migrations
Public namespace Jlorente\DataMigrations Lacodix\LaravelDataMigrations

You must update all application imports and manual provider/class references from the old namespace to the new one. Refresh the application's autoloader and any cached configuration/provider metadata during your normal deployment process.

Keep existing migration filenames, the configured table, rows, batches and directories. For correctly configured 2.x installations, no data rewrite or migration replay is needed for the namespace change. If the required 2.x configuration was not published or otherwise provided, especially with SQLite, verify where existing migration history is stored and point the configuration at that existing history before running new migrations. Class basenames, command names, the data-migrations configuration key and publication tag remain unchanged. If your own code resolves services directly, migration.data.repository and migrator.data remain the same.

The 3.x candidate includes the command-registration fix from upstream PR10. It preserves Laravel's native migrate:install command on Laravel 13.24+ while migrate-data:install and migrate-data:rollback retain their inherited command options.

Contributors and AI-assisted changes

composer install
composer test
composer quality

With no local lockfile, Composer resolves current stable dependencies. composer format applies the project's PHP CS Fixer rules. composer quality checks formatting and runs Larastan/PHPStan. Tests use Orchestra Testbench with private generated migration directories and SQLite in memory; no application database or external provider is needed. CI tests stable and lowest installable dependencies on PHP 8.2–8.5 with Laravel 12 and PHP 8.3–8.6 with Laravel 13. The lane helper is for disposable CI manifests only; the package manifest itself has no advisory exceptions.

For AI-assisted work, run the same tests and quality commands and describe the versions actually exercised. Keep native and data command registrations, repository separation, custom configuration and real migration up/down behavior covered. Use isolated SQLite fixtures and explicit paths for experiments. Do not edit already applied migration files to introduce new behavior; add a new migration instead. Verify assumptions about inherited Laravel options against the installed framework, and keep unrelated features outside a compatibility fix.

License

Copyright © 2018 José Lorente Martín jose.lorente.martin@gmail.com. Originally developed as jlorente/laravel-data-migrations.

Licensed under the MIT license. See LICENSE.txt.