ruzaik11/laravel-seeder-tracker

Track Laravel seeders execution like migrations with batch support and status management

v1.0.3 2025-07-04 00:07 UTC

README

Latest Version on Packagist Total Downloads PHP Version Require

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:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. 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