PHP code example of tarunkorat / laravel-migration-squasher

1. Go to this page and download the library: Download tarunkorat/laravel-migration-squasher library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tarunkorat / laravel-migration-squasher example snippets


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,
];
bash
php artisan vendor:publish --provider="TarunKorat\LaravelMigrationSquasher\MigrationSquasherServiceProvider"
bash
php artisan migrations:squash
bash
php artisan migrations:squash --dry-run
bash
# 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

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

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)