Hello everyone

I would like to encourage you all to check out my brand new open source package. Seeder once will run your laravel seeds only once. In other words will prevent of repeating running the same seed many times. Read description on github page to know more. This library works similar to laravel migrations. It will make registry(table) in database of seeded seeders. Seeders that are in this registry will not be run in the future.

Usage in CI:

1. Create some seeder file for example called: SeedersThatWillRunOnlyOnce. Command:

php artisan make:seeder SeedersThatWillRunOnlyOnce

2. Add to you CI script command that will execute above script.

php artisan db:seed –class=SeedersThatWillRunOnlyOnce

3. Inside run method in SeedersThatWillRunOnlyOnce call only those seeds that you want to be run only once. Example:

use Illuminate\Database\Seeder;

class SeedersThatWillRunOnlyOnce extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // Those called classes will be added to registry after executing.
        $this->call(SomeSeeder::class); 
    }
}

4. To classes called in SeedersThatWillRunOnlyOnce add Kdabrow\SeederOnce\SeederOnce trait(this will prevent to run them second time). Example:

use Illuminate\Database\Seeder;
use Kdabrow\SeederOnce\SeederOnce;

class SomeSeeder extends Seeder
{
    use SeederOnce;

    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // Those scripts will not be run second time after first executing.
    }
}

This package needs some improvements:

1. Make compatible with lumen.

2. Extend readme.md to add some examples.

3. Write unit tests instead of functional.

Links:

Packagist

Leave a Comment