Detect and Resolve Laravel Schema Drift with MigrAlign

Published on by

Detect and Resolve Laravel Schema Drift with MigrAlign image

MigrAlign is a Laravel package that finds the differences between your migration files and your actual database, then applies the changes with safeguards based on how risky each change is. It targets schema drift — the gap that opens up when teams edit tables directly, skip a migration, or run divergent environments.

How It Works

MigrAlign reads the intent from your migration files by scanning Schema::create() and Schema::table() calls, then introspects the live schema from information_schema on MySQL or MariaDB. The diff between the two becomes a set of proposed changes. You can preview everything before anything runs:

php artisan migralign:sync --dry-run

Risk Classification

Rather than applying every change the same way, MigrAlign sorts each change into one of three categories:

  • Safe: adding nullable columns, widening column sizes, and metadata-only changes.
  • Risky: shrinking a type, switching a column from nullable to not-null, or contracting an enum.
  • Destructive: dropping columns or tables.

Safe changes are applied automatically when auto_apply_safe is enabled. Risky and destructive changes prompt for confirmation before MigrAlign touches the database, so a forgotten drop doesn't run unattended.

Targeted Syncing

You can scope a sync to a single table or migration instead of the whole schema, which is useful when you only need to reconcile one area:

# Sync a specific table
php artisan migralign:sync --table=users
 
# Sync changes from a specific migration
php artisan migralign:sync --migration=2024_01_01
 
# Apply all changes without prompts
php artisan migralign:sync --force

After a run, MigrAlign reports each change as applied, skipped, pending, or errored.

Installation and Configuration

Install the package via Composer and publish the config file:

composer require migralign/laravel-migralign
php artisan vendor:publish --tag=migralign-config

The published config controls which migrations path is read, which tables to ignore, and whether safe changes apply automatically:

return [
'migrations_path' => database_path('migrations'),
'ignored_tables' => ['migrations', 'sessions', 'jobs', 'failed_jobs'],
'auto_apply_safe' => true,
'connection' => null,
];

MigrAlign requires PHP 8.2+ (8.3+ on Laravel 13) and supports Laravel 11, 12, and 13. It works with MySQL and MariaDB only, and migrations with highly dynamic logic may still need manual review.

You can learn more and view the source on GitHub.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Filed in:
Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit

The latest

View all →
In-Memory Eloquent Models with Truffle image

In-Memory Eloquent Models with Truffle

Read article
Laravel Cloud Adds Scale-to-Zero and Spending Limits image

Laravel Cloud Adds Scale-to-Zero and Spending Limits

Read article
Shift + AI = Fully Automated Laravel Upgrades image

Shift + AI = Fully Automated Laravel Upgrades

Read article
Laracon AU 2026 Announces Full Speaker Lineup, Schedule, and Workshops image

Laracon AU 2026 Announces Full Speaker Lineup, Schedule, and Workshops

Read article
Parsel: Parse PDFs, Office Documents, and Images in PHP image

Parsel: Parse PDFs, Office Documents, and Images in PHP

Read article
Typed Objects for Eloquent with Expressive image

Typed Objects for Eloquent with Expressive

Read article