riftweb / superseeder
Supercharge your Laravel database seeding with execution tracking and rollbacks! This package adds migration-like behavior to seeders, preventing duplicate runs while enabling batch management and safe rollback of seeded data. Perfect for production environments and complex seeding workflows.
Requires
- php: ^8.0
- illuminate/database: ^8.0|^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^6.23|^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.4|^10.1
README
A robust database seeder solution for Laravel with execution tracking and rollback capabilities. Brings migration-like behavior to your seeders! 🔄
Features ✨
- ✅ Track executed seeders in
seeder_executions
table - ⏮️ Rollback seeders like migrations
- 🛡️ Prevent accidental duplicate executions
- 🔄 Batch management of seeders
- 🚦 Bypass mode for emergency executions
- 🚀 Generator command for trackable seeders
Installation 💻
Install via Composer:
composer require riftweb/superseeder
Run migrations (creates seeder_executions
table):
php artisan migrate
Usage 🛠️
1. Create Trackable Seeder
php artisan make:superseeder UsersSeeder
2. Implement Seeder Logic
<?php namespace Database\Seeders; use Illuminate\Database\Seeder; use Riftweb\SuperSeeder\Traits\TrackableSeed; class UsersSeeder extends Seeder { use TrackableSeed; public function up() { // Your seeder logic } public function down(): void { // Your rollback logic } }
3. Run Seeders
php artisan superseed
4. Rollback Last Batch
php artisan superseed:rollback
Configuration ⚙️
Bypass Mode
Add to .env
:
SUPERSEED_BYPASS=true
What it does:
- When enabled, runs seeders regardless if they have been executed before (use with caution)
- DOES create records in
seeder_executions
- Alternative: Use
--force
flag withsuperseed
command
How It Works 🔍
-
Tracking Table
The package creates aseeder_executions
table to track:- Seeder class name
- Batch number
- Execution timestamp
-
Rollback Process
- Calls
down()
method on each seeder - Deletes tracking records for the batch
- Runs in reverse order of execution
- Calls
Workflow Example 🔄
# 1. Create seeder php artisan make:superseeder UsersSeeder # 2. Implement up() and down() methods # 3. Run seeders php artisan superseed # 4. Rollback php artisan superseed:rollback
Commands 🛠️
Create trackable seeder
php artisan make:superseeder SeederName
Run seeders
php artisan superseed
Rollback seeders
php artisan superseed:rollback
Clear all seeder records
php artisan superseed:fresh
Clear all seeder records and rollback
php artisan superseed:clear
Important Notes ⚠️
- Test rollbacks thoroughly before production use
- Backup database before running seeders
Contributing 🤝
Contributions are welcome! Please follow:
- Fork the repository
- Create your feature branch
- Commit changes
- Push to the branch
- Open a PR
License 📄
MIT License - See LICENSE for details.
Crafted with ❤️ by RIFT | Web Development