ruzaik11 / laravel-seeder-tracker
Track Laravel seeders execution like migrations with batch support and status management
Requires
- php: ^8.1
- illuminate/console: ^9.0|^10.0|^11.0|^12.0
- illuminate/database: ^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- mockery/mockery: ^1.4
- orchestra/testbench: ^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.5|^10.0
This package is not auto-updated.
Last update: 2025-07-04 07:12:33 UTC
README
Track your Laravel seeders execution like migrations with batch support, execution time tracking, and comprehensive status management.
โจ Why Use Seeder Tracker?
In large Laravel applications, managing database seeders becomes complex:
- Duplicate executions can corrupt data or waste time
- No visibility into which seeders have run
- Performance issues go unnoticed
- Environment differences cause inconsistencies
Seeder Tracker solves these problems by bringing migration-like tracking to your seeders!
๐ Features
- ๐ Migration-like tracking - Know exactly which seeders have run
- โฑ๏ธ Performance monitoring - Track execution time and memory usage
- ๐ Batch management - Group related seeder executions
- ๐ก๏ธ Duplicate prevention - Prevent accidental re-runs in production
- ๐ Rich analytics - Detailed performance insights and reporting
- ๐ฏ Environment-aware - Smart controls based on your environment
- ๐พ Metadata storage - Store custom data from seeder results
- ๐ Auto-discovery - Automatically find and track all project seeders
๐ฆ Installation
Install via Composer:
composer require ruzaik11/laravel-seeder-tracker
Publish configuration and migrations:
php artisan vendor:publish --provider="Ruzaik\SeederTracker\SeederTrackerServiceProvider"
php artisan migrate
๐ฏ Quick Start
1. Create a Trackable Seeder
Replace Seeder
with TrackableSeeder
:
<?php namespace Database\Seeders; use Ruzaik\SeederTracker\Seeders\TrackableSeeder; use App\Models\User; class UsersTableSeeder extends TrackableSeeder { protected function seedData() { // Your seeding logic $users = User::factory(100)->create(); // Return metadata for tracking return [ 'users_created' => $users->count(), 'admin_users' => $users->where('is_admin', true)->count(), ]; } }
2. Run Your Seeders
php artisan db:seed --class=UsersTableSeeder
# โ
Seeder UsersTableSeeder executed successfully in 1,234ms
3. Check Execution Status
php artisan seeder:status
๐ Seeder Execution Status
+------------------+-------------+------------------+-------+
| Seeder | Status | Executed At | Batch |
+------------------+-------------+------------------+-------+
| UsersTableSeeder | โ
Executed | Dec 21, 2024 14:30 | 1 |
| ProductSeeder | โณ Pending | Not executed | N/A |
+------------------+-------------+------------------+-------+
Summary: 1/2 seeders executed
๐ Available Commands
Status Management
# Basic status php artisan seeder:status # Detailed view with performance metrics php artisan seeder:status --detailed # Reset specific seeder php artisan seeder:status --reset=UsersTableSeeder # Reset all tracking (with confirmation) php artisan seeder:status --reset-all
Performance Analytics
# Show performance insights php artisan seeder:performance # Limit results php artisan seeder:performance --limit=5
๐ง Advanced Usage
Environment-Aware Seeding
use Ruzaik\SeederTracker\Traits\SeederHelper; class ProductionDataSeeder extends TrackableSeeder { use SeederHelper; protected function seedData() { // Only run in specific environments return $this->runInEnvironments(['production', 'staging'], function () { // Production-specific seeding logic return ['production_data_created' => true]; }); } }
Performance Optimization
protected function seedData() { $startCount = $this->getTableCount('products'); // Batch insert for better performance Product::insert($this->generateProductData(1000)); return [ 'products_created' => $this->getTableCount('products') - $startCount, 'batch_size' => 1000, 'optimization' => 'batch_insert_used', ]; }
Transaction Safety
protected function seedData() { return DB::transaction(function () { // All seeding logic in transaction $categories = Category::createMany($this->categoryData()); $products = Product::createMany($this->productData()); return [ 'categories_created' => count($categories), 'products_created' => count($products), 'transaction_safe' => true, ]; }); }
โ๏ธ Configuration
Customize behavior in config/seeder-tracker.php
:
return [ // Database table for tracking 'table' => 'seeder_tracking', // Enable automatic tracking 'auto_track' => true, // Prevent duplicate executions 'prevent_duplicates' => env('SEEDER_PREVENT_DUPLICATES', true), // Strict environments (always prevent duplicates) 'strict_environments' => ['production'], ];
๐ Performance Monitoring
Track seeder performance automatically:
php artisan seeder:performance
๐ Performance Summary
Total executions: 15
Average execution time: 1,247ms
Total time spent: 18.7s
Average memory usage: 12.3MB
๐ Slowest Seeders
+------------------+----------------+-------------+------------------+
| Seeder | Execution Time | Memory Used | Executed At |
+------------------+----------------+-------------+------------------+
| ProductSeeder | 3,456ms | 25.4MB | Dec 21, 14:30 |
| UsersTableSeeder | 2,123ms | 15.7MB | Dec 21, 14:25 |
+------------------+----------------+-------------+------------------+
๐ Fastest Seeders
+------------------+----------------+-------------+------------------+
| Seeder | Execution Time | Memory Used | Executed At |
+------------------+----------------+-------------+------------------+
| RoleSeeder | 45ms | 2.1MB | Dec 21, 14:20 |
| SettingSeeder | 67ms | 3.2MB | Dec 21, 14:22 |
+------------------+----------------+-------------+------------------+
๐งช Testing
The package includes comprehensive tests:
# Run tests composer test # Run with coverage composer test-coverage
๐ Examples
Check the examples/
directory for:
- Basic seeder implementation
- Advanced environment-aware seeding
- Performance optimization techniques
- Transaction handling patterns
๐ง Troubleshooting
See TROUBLESHOOTING.md for common issues and solutions.
๐ Development Journey
This package was developed over 3+ months with focus on:
- October 2024: Foundation and core architecture
- November 2024: Tracking logic and performance monitoring
- December 2024: Enhanced commands and comprehensive documentation
- January 2025: Community feedback and optimization
๐ค Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Submit a pull request
๐ License
MIT License. See LICENSE for details.
๐จโ๐ป Credits
- Ruzaik Nazeer - Creator and maintainer
- Laravel Community - Inspiration and feedback
Built with โค๏ธ for the Laravel community
Website โข
Email โข
Packagist