Download the PHP package zitansmail/migration-orderer without Composer
On this page you can find all versions of the php package zitansmail/migration-orderer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zitansmail/migration-orderer
More information about zitansmail/migration-orderer
Files in zitansmail/migration-orderer
Package migration-orderer
Short Description Automatically order Laravel migrations based on foreign key dependencies to prevent constraint errors
License MIT
Homepage https://github.com/zitansmail/laravel-migration-orderer
Informations about the package migration-orderer
๐ฆ MigrationOrderer โ Dependency-Aware Laravel Migration Ordering
Automatically analyze and reorder Laravel migrations based on foreign key dependencies. Prevent foreign key constraint errors by ensuring tables are created in the correct order.
๐ฏ The Problem
Ever encountered this error when running migrations?
This happens when migrations create foreign keys to tables that don't exist yet. Traditional solutions require manually renaming migration files or creating migrations in perfect chronological order.
๐ก The Solution
MigrationOrderer automatically:
- Scans your migrations for foreign key dependencies
- Builds a dependency graph using topological sorting
- Reorders files to ensure dependencies come first
- Shows you exactly what needs to be fixed
๐ Features
- ๐ Smart Detection: Finds
foreignId(),constrained(),foreignIdFor(), and legacy foreign keys - ๐งฉ Topological Sort: Uses graph algorithms to compute safe execution order
- ๐๏ธ Rich Preview: Shows current vs computed positions with dependency details
- ๐ก๏ธ Circular Detection: Identifies and reports circular dependencies with clear error messages
- ๐ Safe Reordering: Renames files while maintaining full undo capability
- ๐พ State Management: Tracks changes in database for reliable undo operations
- ๐ Flexible Paths: Works with custom migration directories and modular setups
- โ Production Ready: Comprehensive test coverage and error handling
โ Requirements
- PHP 8.1+
- Laravel 10.x / 11.x / 12.x
๐ฆ Installation
That's it! The package auto-registers and creates its tracking table automatically when needed. No manual migrations required.
๐ Usage
1. Preview Dependencies (Safe, No Changes)
Example Output:
2. Reorder Files
With confirmation bypass (CI/automation):
3. Undo Last Reorder
4. Custom Migration Paths
๐ Supported Foreign Key Patterns
The scanner detects all modern Laravel foreign key patterns:
๐ Workflow Examples
Basic Workflow
Team Development
๐จ Error Handling
Circular Dependencies
Solution: Break the cycle by:
- Moving foreign keys to separate migrations
- Using nullable foreign keys initially
- Deferring constraints with
Schema::enableForeignKeyConstraints()
Missing Dependencies
The preview shows missing tables that your migrations reference but don't create:
๐งญ Command Reference
๐ Safety Features
- Preview First: Always shows what will change before making modifications
- Atomic Operations: File renames are tracked; failures can be undone
- State Persistence: Every reorder is logged in the database
- Backup Strategy: Undo capability restores exact previous state
- Non-Destructive: Default mode makes no changes to your files
- Validation: Detects and prevents circular dependencies
๐ก๏ธ Best Practices
Development Workflow
- Always preview first to understand dependencies
- Commit before reordering for easy rollback
- Use feature branches for complex schema changes
- Test migrations in staging before production
Schema Design
- Avoid circular foreign key dependencies
- Consider nullable foreign keys for complex relationships
- Use pivot tables for many-to-many relationships
- Plan table creation order during initial design
Team Collaboration
- Run
--previewbefore pushing migration changes - Include reordering in your CI/CD pipeline
- Document complex dependency relationships
- Use consistent naming conventions
๐งช Testing
The package includes focused tests covering core functionality:
Essential test coverage:
- โ Command Interface - Preview, reorder, undo operations
- โ Dependency Detection - All foreign key patterns and missing dependencies
- โ Circular Dependencies - Detection and error handling
- โ File Operations - Safe reordering with automatic table creation
๐ค Contributing
We welcome contributions! Here's how you can help improve MigrationOrderer:
Quick Start
Contributing Guidelines
๐ Reporting Bugs
- Check existing issues before creating new ones
- Include Laravel version, PHP version, and error details
- Provide minimal reproduction steps
โจ Suggesting Features
- Open an issue with a clear description
- Explain the use case and expected behavior
- Include code examples if applicable
๐ง Code Contributions
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Write tests for new functionality
- Ensure all tests pass:
composer test - Follow PSR-12 coding standards
- Submit a pull request with clear description
๐ Documentation
- Fix typos and improve clarity
- Add examples for complex features
- Update README when adding new functionality
Development Guidelines
- Write tests for all new features
- Keep backwards compatibility
- Follow existing code patterns
- Add meaningful commit messages
๐ License
MIT License. See LICENSE for details.
๐ Learn More
๐ Technical Deep Dive Read the complete story behind MigrationOrderer's development: Solving Laravel Migration Dependency Hell: Building MigrationOrderer Package
The blog post covers:
- The problem and motivation behind the package
- Technical implementation details and algorithms
- Real-world usage patterns and team workflows
- Development challenges and lessons learned
- Future enhancements and roadmap
๐ Credits
Created by Zitane Smail
Built with โค๏ธ for the Laravel community.
All versions of migration-orderer with dependencies
illuminate/database Version ^10.0 || ^11.0 || ^12.0
illuminate/console Version ^10.0 || ^11.0 || ^12.0
illuminate/support Version ^10.0 || ^11.0 || ^12.0