PHPackages                             tarunkorat/laravel-migration-squasher - 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. tarunkorat/laravel-migration-squasher

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

tarunkorat/laravel-migration-squasher
=====================================

Squash old Laravel migrations into a single schema file

v1.0.0(6mo ago)676↓50%[1 issues](https://github.com/tarunkorat/laravel-migration-squasher/issues)MITPHPPHP ^8.0|^8.1|^8.2|^8.3CI failing

Since Oct 30Pushed 6mo agoCompare

[ Source](https://github.com/tarunkorat/laravel-migration-squasher)[ Packagist](https://packagist.org/packages/tarunkorat/laravel-migration-squasher)[ RSS](/packages/tarunkorat-laravel-migration-squasher/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

Laravel Migration Squasher
==========================

[](#laravel-migration-squasher)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a7cf8ccc964d62867d3a3ebfe8670c5ba4a4ac5183a61ef3ca2795fa51f9c3d6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746172756e6b6f7261742f6c61726176656c2d6d6967726174696f6e2d73717561736865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tarunkorat/laravel-migration-squasher)[![Total Downloads](https://camo.githubusercontent.com/a66ddeaf8ed4561f7d3e6ff13d01d17ab79ba98072bbd4cd0d849960f183a7f8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746172756e6b6f7261742f6c61726176656c2d6d6967726174696f6e2d73717561736865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tarunkorat/laravel-migration-squasher)[![License](https://camo.githubusercontent.com/08045a10e1e6c80ff493e6f6781b2d7a55a0c86381daba6c71fb9056f50daf8d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746172756e6b6f7261742f6c61726176656c2d6d6967726174696f6e2d73717561736865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tarunkorat/laravel-migration-squasher)

Squash old Laravel migrations into a single schema file to keep your migrations folder clean and manageable.

**Fully compatible with Laravel 8, 9, 10, 11, and 12!**

✨ Features
----------

[](#-features)

- 🗜️ **Squash old migrations** into a single schema file
- 📅 **Keep recent migrations** separate for easy tracking
- 🔒 **Safe backup** before any deletion
- 🚀 **Faster migrations** - reduce migrate:fresh time by 90%
- 🎯 **Laravel 8-12 compatible** - works with all modern Laravel versions
- 🔍 **Dry run mode** - preview changes before applying
- 🛡️ **Database agnostic** - works with MySQL, PostgreSQL, SQLite, SQL Server
- 📊 **Clean codebase** - reduce migration clutter from 100+ to just a few files

📋 Requirements
--------------

[](#-requirements)

- PHP 8.0 or higher
- Laravel 8.x, 9.x, 10.x, 11.x, or 12.x
- Doctrine DBAL (automatically installed)

📦 Installation
--------------

[](#-installation)

Install the package via composer:

```
composer require tarunkorat/laravel-migration-squasher
```

The package will automatically register itself via Laravel's package discovery.

### Publish Configuration (Optional)

[](#publish-configuration-optional)

```
php artisan vendor:publish --provider="TarunKorat\LaravelMigrationSquasher\MigrationSquasherServiceProvider"
```

This will create `config/migration-squasher.php` file.

🚀 Usage
-------

[](#-usage)

### Basic Usage

[](#basic-usage)

Squash all migrations before a specific date, keeping the 10 most recent:

```
php artisan migrations:squash
```

### Preview Changes (Dry Run)

[](#preview-changes-dry-run)

See what would be squashed without making any changes:

```
php artisan migrations:squash --dry-run
```

### Custom Options

[](#custom-options)

```
# Squash migrations before specific date
php artisan migrations:squash --before=2024-01-01

# Keep specific number of recent migrations
php artisan migrations:squash --keep=15

# Disable backup creation
php artisan migrations:squash --no-backup

# Delete migration records from database
php artisan migrations:squash --delete-records

# Combine multiple options
php artisan migrations:squash --before=2023-06-01 --keep=20 --dry-run
```

⚙️ Configuration
----------------

[](#️-configuration)

The config file provides several options:

```
return [
    // Date before which migrations will be squashed
    'squash_before' => env('MIGRATION_SQUASH_BEFORE', '2024-01-01'),

    // Number of recent migrations to keep separate
    'keep_recent' => (int) env('MIGRATION_SQUASH_KEEP_RECENT', 10),

    // Name of the generated schema dump file
    'schema_file' => '0000_00_00_000000_schema_dump.php',

    // Create backup of squashed migrations
    'backup_migrations' => env('MIGRATION_SQUASH_BACKUP', true),

    // Backup directory path
    'backup_path' => env('MIGRATION_SQUASH_BACKUP_PATH', 'migrations/backup'),

    // Tables to exclude from schema dump
    'excluded_tables' => [
        'migrations',
    ],

    // Delete migration records from database
    'delete_batch_records' => false,
];
```

📊 Before &amp; After Example
----------------------------

[](#-before--after-example)

### Before Squashing

[](#before-squashing)

```
database/migrations/
├── 2022_01_15_100000_create_users_table.php
├── 2022_01_15_100001_create_password_resets_table.php
├── 2022_02_20_140000_create_posts_table.php
├── 2022_02_20_140001_add_slug_to_posts_table.php
... (96 more old files)
├── 2024_10_15_140000_add_thumbnail_to_posts_table.php
├── 2024_10_20_150000_create_notifications_table.php
├── 2024_10_25_160000_add_verified_at_to_users_table.php

```

**Total: 100 migration files** 😰

### After Squashing

[](#after-squashing)

```
database/migrations/
├── 0000_00_00_000000_schema_dump.php          ⭐ (Entire schema in ONE file)
├── 2024_10_15_add_thumbnail_to_posts.php      (Recent - Kept)
├── 2024_10_20_create_notifications.php        (Recent - Kept)
├── 2024_10_25_add_verified_at_to_users.php    (Recent - Kept)

```

**Total: 4 migration files** 🎉

🎯 When to Use This Package
--------------------------

[](#-when-to-use-this-package)

### ✅ Perfect For:

[](#-perfect-for)

- **Long-running projects** (1+ years old with 50+ migrations)
- **Performance optimization** (speed up `migrate:fresh` by 90%)
- **Team onboarding** (new developers see clean migration history)
- **CI/CD pipelines** (faster test suite execution)
- **Before major releases** (clean slate for v2.0)

### ❌ Not Recommended For:

[](#-not-recommended-for)

- **New projects** (&lt; 6 months old with few migrations)
- **Active feature branches** (wait until merged to avoid conflicts)
- Projects that never run `migrate:fresh`

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

[](#-how-it-works)

1. **Analyzes** all migrations in your project
2. **Identifies** migrations older than specified date
3. **Keeps** the most recent N migrations separate
4. **Generates** a schema dump from your current database structure
5. **Creates** backup of squashed migrations (optional)
6. **Deletes** old migration files
7. **Updates** migrations table (optional)

### Important Notes

[](#important-notes)

- ✅ Your **database stays exactly the same** - no data is modified
- ✅ Only **migration files** are affected
- ✅ Always creates **backups** before deletion (unless disabled)
- ✅ Safe to run - uses **dry-run mode** first

🧪 Testing
---------

[](#-testing)

```
composer test
```

📈 Performance Comparison
------------------------

[](#-performance-comparison)

MetricBefore SquashAfter SquashImprovementMigration Files167 files11 files**93% reduction**`migrate:fresh` Time8 minutes45 seconds**90% faster**CI/CD Pipeline2 min migrations30 sec migrations**75% faster**Codebase ClarityClutteredClean**Much better**🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

📝 Changelog
-----------

[](#-changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

🔒 Security
----------

[](#-security)

If you discover any security related issues, please email  instead of using the issue tracker.

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

💡 Credits
---------

[](#-credits)

- [Tarun Korat](https://github.com/tarunkorat)
- [All Contributors](../../contributors)

🙏 Support
---------

[](#-support)

If you find this package helpful, please consider:

- ⭐ Starring the repository
- 🐛 Reporting bugs and issues
- 📖 Contributing to documentation
- 💬 Sharing with other Laravel developers

---

Made with ❤️ for the Laravel community

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance64

Regular maintenance activity

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

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

Unknown

Total

1

Last Release

194d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/44538ddc1b10186c30a1c6f8d2c9b3201f3b26bf601fff1b4d17d7e755aa7a43?d=identicon)[tarunkorat](/maintainers/tarunkorat)

---

Top Contributors

[![tarunkorat](https://avatars.githubusercontent.com/u/108346132?v=4)](https://github.com/tarunkorat "tarunkorat (9 commits)")

---

Tags

laravelschemalaravel 8laravel 9laravel 10laravel 11laravel 12databasemigrationssquash

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tarunkorat-laravel-migration-squasher/health.svg)

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

###  Alternatives

[aws/aws-sdk-php-laravel

A simple Laravel 9/10/11/12/13 service provider for including the AWS SDK for PHP.

1.7k35.6M75](/packages/aws-aws-sdk-php-laravel)[dragon-code/laravel-data-dumper

Adding data from certain tables when executing the `php artisan schema:dump` console command

3418.6k](/packages/dragon-code-laravel-data-dumper)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[orptech/laravel-migration-partition

Laravel extensions that extends Illuminate to enable partitioned table creation within Laravel migrations.

3426.7k](/packages/orptech-laravel-migration-partition)[itsmurumba/laravel-mpesa

Laravel Package for Mpesa Daraja API

191.6k](/packages/itsmurumba-laravel-mpesa)

PHPackages © 2026

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