zitansmail / migration-orderer
Order Laravel migrations before execution
dev-main
2025-09-20 18:07 UTC
Requires
- php: ^8.1
- illuminate/database: ^10.0 || ^11.0 || ^12.0
Requires (Dev)
- orchestra/testbench: ^10.6
- pestphp/pest: ^3.8
This package is auto-updated.
Last update: 2025-09-20 18:07:41 UTC
README
Automatically orders Laravel migration files based on database dependency relationships to eliminate foreign key constraint errors
composer require zitansmail/migration-orderer
🚀 Key Features
- 🔍 Dependency Scanning - Detects foreign keys across migration files
- 🧠 Graph Processing - Builds dependency graph with topological sorting
- 🔄 File Renaming - Rewrites timestamps to enforce execution order (
--reorder
) - 📋 Database Sync - Updates
migrations
table when files change - ⚙️ Migration Execution - Runs migrations in resolved order (
--run
) - 👁️ Dry Run Previews - Simulate changes without modifications (
--dry-run
) - 📊 JSON Output - Machine-readable dependency graph (
--json
) - 📂 Custom Paths - Processes non-standard directories (
--path=
)
📦 Installation
- Install via Composer:
composer require zitansmail/migration-orderer
- If Laravel doesn't auto-discover the package, register the service provider in
config/app.php
:
'providers' => [ // Other service providers... MigrationOrderer\MigrationOrdererServiceProvider::class, ],
🛠 Usage Examples
Preview migration order (no changes)
php artisan migrate:ordered --dry-run
Generate dependency graph (JSON format)
php artisan migrate:ordered --dry-run --json
Process migrations in custom directory
php artisan migrate:ordered --path=database/migrations/v2 --dry-run
Reorder & rename migrations
php artisan migrate:ordered --reorder
Execute migrations in resolved order
php artisan migrate:ordered --run
⚠️ Best Practices
- Always preview with
--dry-run
before executing changes - Commit your work before using
--reorder
or--run
- Test thoroughly after reordering migrations
- Document custom paths for team members
- Resolve circular dependencies before processing
- Avoid production use - Recommended for development only
📝 License
MIT License - https://opensource.org/licenses/MIT
⚙️ Contributing
PRs welcome! See Contribution Guide for:
- Bug reports
- Feature requests
- Code style requirements
- Testing guidelines
Pro Tip: Combine with Laravel's migration commands:
php artisan migrate:ordered --reorder php artisan migrate:fresh --seed php artisan migrate:refresh --seed
MigrationOrderer is not affiliated with The Laravel Framework. Laravel is a trademark of Taylor Otwell.