PHPackages                             abdullahkaram-dev/laravel-migration-sorter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. abdullahkaram-dev/laravel-migration-sorter

ActiveLibrary[Database &amp; ORM](/categories/database)

abdullahkaram-dev/laravel-migration-sorter
==========================================

Interactive Laravel migration file sorting with drag and drop functionality

v1.0.2(10mo ago)34MITPHPPHP ^8.1

Since Jul 2Pushed 10mo agoCompare

[ Source](https://github.com/AbdullahKaram-Dev/laravel-migration-sorter)[ Packagist](https://packagist.org/packages/abdullahkaram-dev/laravel-migration-sorter)[ Docs](https://github.com/AbdullahKaram-Dev/laravel-migration-sorter)[ RSS](/packages/abdullahkaram-dev-laravel-migration-sorter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (4)Used By (0)

🔄 Laravel Migration Sorter
==========================

[](#-laravel-migration-sorter)

[![GitHub stars](https://camo.githubusercontent.com/3ab4a3b335edb665ba391249a7491596d38ec6a369fdaa923aeb73d3c8322aa8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f416264756c6c61684b6172616d2d4465762f6c61726176656c2d6d6967726174696f6e2d736f727465723f7374796c653d666c61742d737175617265266c6f676f3d676974687562)](https://github.com/AbdullahKaram-Dev/laravel-migration-sorter/stargazers)[![Packagist Downloads](https://camo.githubusercontent.com/afd031bba78a3b1a28dde6bbe1f298f06495f784ae4e747ea299d5cdd8ad9e7e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616264756c6c61686b6172616d2d6465762f6c61726176656c2d6d6967726174696f6e2d736f727465723f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374)](https://packagist.org/packages/abdullahkaramdev/migration-sorter)[![Laravel Version](https://camo.githubusercontent.com/ef38a36a6d847eee713d47aabf857c5254560ae4abc2724edcee3e855d7c60ef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d382e302532422d7265643f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c)](https://laravel.com)[![Latest Version on Packagist](https://camo.githubusercontent.com/52784d05227b3879e6c8f4a3c0eb6491a077d162c12de3cb78c77255be0791d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616264756c6c61686b6172616d2d6465762f6c61726176656c2d6d6967726174696f6e2d736f727465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/abdullahkaram-dev/laravel-migration-sorter)

An interactive Laravel command for sorting database migration files with drag-and-drop functionality and automatic timestamp regeneration.

[![Migration Sorter Interface](https://raw.githubusercontent.com/AbdullahKaram-Dev/laravel-migration-sorter/refs/heads/master/preview.webp)](https://raw.githubusercontent.com/AbdullahKaram-Dev/laravel-migration-sorter/refs/heads/master/preview.webp)

🤔 Why Use This Command?
-----------------------

[](#-why-use-this-command)

### ❌ Common Migration Problems

[](#-common-migration-problems)

- **Out-of-order migrations** causing database schema conflicts 🔀
- **Foreign key constraint errors** when child tables with foreign keys are created before their parent tables 🔗❌
- **Timestamp conflicts** when multiple developers create migrations simultaneously ⏰💥
- **Dependency issues** where migrations depend on tables created in later migrations 🔄⚠️
- **Messy migration history** making it difficult to understand database evolution 📂🌪️
- **Production deployment failures** due to incorrect migration execution order 🚀💥

### ✅ Solutions This Package Provides

[](#-solutions-this-package-provides)

- **Visual migration management** - See all your migrations in one organized view 👁️📊
- **Interactive reordering** - Drag and drop migrations to the correct sequence 🖱️✨
- **Automatic timestamp fixing** - Regenerates timestamps to ensure proper execution order ⏰🔧
- **Safe operations** - Creates backups before making any changes 🛡️💾
- **Team collaboration** - Ensures consistent migration order across all environments 👥🤝
- **Time-saving** - No more manual file renaming or timestamp calculations ⚡💯

### 🌟 Real-World Scenarios

[](#-real-world-scenarios)

1. **After merging branches** - Sort conflicting migration timestamps from multiple feature branches 🌿🔀
2. **Before production deployment** - Ensure migrations will execute in the correct logical order 🚀✅
3. **Database refactoring** - Reorganize migrations to match your current database structure needs 🏗️🔧
4. **Team onboarding** - Help new developers understand the database evolution timeline 👨‍💻📈
5. **Migration cleanup** - Organize legacy migrations for better maintainability 🧹✨

Features
--------

[](#features)

### Interactive Terminal Interface

[](#interactive-terminal-interface)

- **Visual file browser** with table display showing migration files
- **Real-time navigation** using arrow keys or keyboard shortcuts
- **Drag-and-drop functionality** for manual file reordering
- **Cross-platform support** (Windows, Linux, macOS)

### Multiple Sorting Options

[](#multiple-sorting-options)

- **Sort by Name** (A-Z or Z-A)
- **Sort by Date** (Newest first or Oldest first)
- **Sort by File Size** (Largest first or Smallest first)
- **Manual drag-and-drop** for custom ordering

### File Information Display

[](#file-information-display)

- Migration file names (truncated for readability)
- File sizes in human-readable format
- Last modified timestamps
- Visual indicators for selected and grabbed files

### Safe File Operations

[](#safe-file-operations)

- **Automatic backup** creation before any changes
- **Timestamp regeneration** with sequential ordering
- **Rollback capability** using backup files
- **Confirmation prompts** before destructive operations

Installation
------------

[](#installation)

### Via Composer

[](#via-composer)

```
composer require abdullahkaram-dev/laravel-migration-sorter
```

### Manual Installation

[](#manual-installation)

1. Copy the `SortingMigration.php` command to your Laravel project
2. Register the command in your `app/Console/Kernel.php`:

```
protected $commands = [
    \AbdullahKaramDev\MigrationSorter\Commands\SortingMigration::class,
];
```

Usage
-----

[](#usage)

### Basic Command

[](#basic-command)

```
php artisan rearrange-migrations
```

### Interactive Controls

[](#interactive-controls)

#### Universal Controls

[](#universal-controls)

- **Q** - Quit the application
- **R** - Reset to original order
- **ENTER** - Finish sorting and regenerate files
- **ESC** - Cancel current operation

#### Navigation Controls

[](#navigation-controls)

**Linux/macOS:**

- **↑/↓ Arrow Keys** - Navigate up/down through files
- **SPACE** - Grab/Drop files for reordering

**Windows:**

- **W** - Move selection up
- **S** - Move selection down
- **GRAB** - Grab selected file
- **DROP** - Drop grabbed file at current position

#### Sorting Shortcuts

[](#sorting-shortcuts)

- **N** - Sort by name (with direction prompt)
- **D** - Sort by date (with direction prompt)
- **SIZE** - Sort by file size (with direction prompt)

### Sorting Directions

[](#sorting-directions)

When using automatic sorting, you'll be prompted to choose:

#### Ascending Options

[](#ascending-options)

- **Name**: A to Z alphabetical order
- **Date**: Oldest files first
- **Size**: Smallest files first

#### Descending Options (Default)

[](#descending-options-default)

- **Name**: Z to A reverse alphabetical
- **Date**: Newest files first
- **Size**: Largest files first

How It Works
------------

[](#how-it-works)

### File Detection

[](#file-detection)

1. Scans the `database/migrations` directory
2. Identifies all `.php` migration files
3. Extracts file metadata (size, modification date)
4. Displays files in an interactive table format

### Drag-and-Drop Process

[](#drag-and-drop-process)

1. Navigate to desired file using arrow keys
2. Press **SPACE** (or type **GRAB**) to select file
3. Navigate to target position
4. Press **SPACE** (or type **DROP**) to place file
5. Repeat for additional reordering

### File Regeneration

[](#file-regeneration)

1. Creates timestamped backup in `storage/app/migration_backups/`
2. Generates new sequential timestamps starting from current time
3. Renames all migration files with new timestamps
4. Preserves original migration class names and content
5. Shows progress bars for backup and regeneration processes

File Structure
--------------

[](#file-structure)

### Before Sorting

[](#before-sorting)

```
database/migrations/
├── 2023_01_15_120000_create_users_table.php
├── 2024_03_20_140000_create_posts_table.php
├── 2024_01_10_100000_create_categories_table.php
└── 2024_02_28_160000_add_foreign_keys.php

```

### After Sorting (by Date, Ascending)

[](#after-sorting-by-date-ascending)

```
database/migrations/
├── 2025_07_02_120000_create_users_table.php      # Original: 2023_01_15
├── 2025_07_02_120001_create_categories_table.php # Original: 2024_01_10
├── 2025_07_02_120002_add_foreign_keys.php        # Original: 2024_02_28
└── 2025_07_02_120003_create_posts_table.php      # Original: 2024_03_20

```

Backup System
-------------

[](#backup-system)

### Automatic Backups

[](#automatic-backups)

- Created before any file modifications
- Stored in `storage/app/migration_backups/YYYY-MM-DD_HH-mm-ss/`
- Contains exact copies of original migration files
- Preserves original timestamps and content

### Backup Directory Structure

[](#backup-directory-structure)

```
storage/app/migration_backups/
└── 2025-07-02_14-30-15/
    ├── 2023_01_15_120000_create_users_table.php
    ├── 2024_01_10_100000_create_categories_table.php
    ├── 2024_02_28_160000_add_foreign_keys.php
    └── 2024_03_20_140000_create_posts_table.php

```

Safety Features
---------------

[](#safety-features)

### Confirmation Prompts

[](#confirmation-prompts)

- Asks before regenerating migration files
- Displays backup location information
- Shows progress indicators during operations

### Error Handling

[](#error-handling)

- Validates migration directory existence
- Handles file permission issues
- Provides detailed error messages
- Maintains original files on failure

### Rollback Process

[](#rollback-process)

If you need to restore original migrations:

1. Navigate to the backup directory shown after regeneration
2. Copy files back to `database/migrations/`
3. Remove the regenerated files

Display Information
-------------------

[](#display-information)

### File Table Columns

[](#file-table-columns)

- **\#** - Sequential index number
- **Select** - Radio button indicator (● for selected, ○ for unselected)
- **Migration File Name** - Truncated filename for readability
- **Size** - Human-readable file size
- **Modified Date** - Last modification timestamp
- **Status** - Shows "GRABBED" when file is selected for moving

### Visual Indicators

[](#visual-indicators)

- **Yellow highlighting** for currently selected file
- **Green status messages** for successful operations
- **Red error messages** for failures
- **Cyan informational text** for instructions

Technical Requirements
----------------------

[](#technical-requirements)

### Laravel Version

[](#laravel-version)

- Laravel 8.0 or higher
- PHP 7.4 or higher

### Dependencies

[](#dependencies)

- `illuminate/console` - For command interface
- `illuminate/support` - For collections and utilities
- `carbon/carbon` - For timestamp manipulation

### System Requirements

[](#system-requirements)

- Terminal with keyboard input support
- Read/write permissions for migrations directory
- Storage directory access for backups

Troubleshooting
---------------

[](#troubleshooting)

### Common Issues

[](#common-issues)

#### "Directory not found" Error

[](#directory-not-found-error)

```
Directory not found: /path/to/database/migrations
```

**Solution**: Ensure you're running the command from your Laravel project root

#### "No migration files found" Message

[](#no-migration-files-found-message)

```
No migration files found in 'database/migrations'
Try creating some migration files first with: php artisan make:migration
```

**Solution**: Create migration files first or check directory permissions

#### Windows Key Input Issues

[](#windows-key-input-issues)

**Problem**: Arrow keys not working on Windows **Solution**: Use W/S keys for navigation and type full commands

### Permission Issues

[](#permission-issues)

If you encounter permission errors:

1. Check file permissions: `chmod 755 database/migrations`
2. Verify storage directory access: `chmod 755 storage/app`
3. Ensure Laravel has write permissions

Advanced Usage
--------------

[](#advanced-usage)

### Custom Base Timestamp

[](#custom-base-timestamp)

The regeneration process uses the current timestamp as base. Files are given sequential timestamps (base + 0 seconds, base + 1 second, etc.)

### Integration with Version Control

[](#integration-with-version-control)

1. Run migration sorting in development environment
2. Commit the reordered migration files
3. Team members will receive properly ordered migrations
4. Backup files are automatically excluded from version control

Contributing
------------

[](#contributing)

### Development Setup

[](#development-setup)

1. Clone the repository
2. Install dependencies: `composer install`
3. Follow PSR-12 coding standards

### Feature Requests

[](#feature-requests)

- Submit issues on GitHub with detailed descriptions
- Include use cases and expected behavior
- Provide sample migration files if relevant

License
-------

[](#license)

This package is open-sourced software licensed under the MIT license. See the [LICENSE](https://github.com/AbdullahKaram-Dev/laravel-migration-sorter/blob/master/LICENSE.md) file for more details.

Support
-------

[](#support)

For issues and questions:

- GitHub Issues: Report bugs and feature requests
- Documentation: Check this README for common solutions
- Laravel Community: General Laravel migration questions

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance54

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

314d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/116cf97ca5c20d854b70770623b00e390a96b40cc3cd8c9ccd4ab57e99e63560?d=identicon)[AbdullahKaram-Dev](/maintainers/AbdullahKaram-Dev)

---

Top Contributors

[![AbdullahKaram-Dev](https://avatars.githubusercontent.com/u/61882285?v=4)](https://github.com/AbdullahKaram-Dev "AbdullahKaram-Dev (11 commits)")

---

Tags

laravelmigrationartisancommandsorting

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/abdullahkaram-dev-laravel-migration-sorter/health.svg)

```
[![Health](https://phpackages.com/badges/abdullahkaram-dev-laravel-migration-sorter/health.svg)](https://phpackages.com/packages/abdullahkaram-dev-laravel-migration-sorter)
```

###  Alternatives

[xethron/migrations-generator

Generates Laravel Migrations from an existing database

3.3k3.3M25](/packages/xethron-migrations-generator)[dragon-code/laravel-deploy-operations

Performing any actions during the deployment process

240173.5k2](/packages/dragon-code-laravel-deploy-operations)[nwidart/db-exporter

Export your database quickly and easily as a Laravel Migration and all the data as a Seeder class.

37839.1k](/packages/nwidart-db-exporter)[maxim-oleinik/blade-migrations-laravel

An intelligent alternative version of Laravel Database Migrations - uses raw-sql syntax, transactions, auto-rollback, UP-DOWN-UP testing

242.3k](/packages/maxim-oleinik-blade-migrations-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
