Looking to hire Laravel developers? Try LaraJobs

laravel-seed-migrations maintained by mahbuburriad

Description
Versioned database seeders for Laravel — like migrations, but for seed data.
Author
Mahbubur Riad
Last update
2026/03/27 11:20 (dev-master)
License
Links
Downloads
22

Comments
comments powered by Disqus

laravel-seed-migrations

Versioned database seeders for Laravel — just like migrations, but for seed data.

Packagist License: MIT Downloads Monthly GitHub stars

The Problem

You need to push settings, config values, or default data to your database — but php artisan db:seed always re-runs everything. There's no way to track what's already been seeded.

The Solution

This package gives you versioned seeders — each one runs exactly once, tracked in a database table, just like migrations.


Installation

composer require mahbuburriad/laravel-seed-migrations

The service provider auto-registers via Laravel's package discovery.

Run the package migration to create the tracking table:

php artisan migrate

Upgrading from v1.x

If you are upgrading from v1.x, run php artisan migrate after updating. The included migration will rename your existing seed_migration_versions table to seeds, preserving all tracked data. No manual steps required.

See CHANGELOG.md for the full list of breaking changes.


Usage

1. Create a versioned seeder

php artisan seed:make 1.0 --desc="Initial settings"

This creates database/seeders/versions/SeedVersion_1_0.php:

<?php

namespace Database\Seeders\Versions;

use Illuminate\Support\Facades\DB;
use Mahbuburriad\SeedMigrations\Contracts\VersionedSeeder;

class SeedVersion_1_0 extends VersionedSeeder
{
    public function version(): string
    {
        return '1.0';
    }

    public function description(): string
    {
        return 'Initial settings';
    }

    public function run(): void
    {
        DB::table('settings')->insert([
            ['key' => 'app_name', 'value' => 'MyApp'],
            ['key' => 'theme',    'value' => 'light'],
        ]);
    }

    public function rollback(): void
    {
        DB::table('settings')
            ->whereIn('key', ['app_name', 'theme'])
            ->delete();
    }
}

2. Run pending seeders

php artisan seed:migrate

Only versions that have not run yet will execute. Exits cleanly with no error when nothing is pending — safe for CI/CD pipelines.

3. Run a specific version

php artisan seed:migrate --seed-version=1.1

4. Dry run (preview without saving)

php artisan seed:migrate --dry-run

5. Check status

php artisan seed:status

Output:

+----------+------------------+---------+---------------------+
| Version  | Description      | Status  | Run At              |
+----------+------------------+---------+---------------------+
| 1.0      | Initial settings | Ran     | 2025-01-01 10:00:00 |
| 1.1      | Add new keys     | Pending | —                   |
+----------+------------------+---------+---------------------+

  Total: 2  |  Ran: 1  |  Pending: 1

6. Rollback

# Rollback the last run version
php artisan seed:rollback

# Rollback a specific version
php artisan seed:rollback --seed-version=1.1

# Skip the confirmation prompt (for scripts / CI)
php artisan seed:rollback --force

Commands Summary

Command Description
seed:make {version} Create a new versioned seeder
seed:migrate Run all pending seed versions
seed:migrate --seed-version=x.x Run a specific version only
seed:migrate --dry-run Preview without running
seed:rollback Roll back the last version
seed:rollback --seed-version=x.x Roll back a specific version
seed:rollback --force Roll back without confirmation
seed:status Show all versions and their status

Configuration

Publish the config file:

php artisan vendor:publish --tag=seed-migrations-config

config/seed-migrations.php:

return [
    'table' => env('SEED_MIGRATIONS_TABLE', 'seeds'), // DB tracking table
    'path'  => database_path('seeders/versions'),      // Where seeder files live
];

You can also override the table name without publishing the config:

SEED_MIGRATIONS_TABLE=seeds

Versioning Convention

Use semantic versioning for your seeders:

1.0  → Initial data
1.1  → Added new settings key
2.0  → Major data restructure
2.1  → Corrected a value

Files are sorted and run in semantic version order, so 1.0 always runs before 2.0.


License

MIT © Mahbubur Riad